-1

Let's say I have a base class User that holds all the necessary info (login, name, mail ...). There's Administrator class deriving from User that can create new and delete existing Users.

I need 3 more classes: Manager, Worker and Project. Both Manager and Worker derive from User but there's no need for additional members or methods within these which makes them empty classes.

In terms of visual representation I find this clear to understand if I aggregate Manager and Worker to the Project like this:

class diagram bit - aggregation

The thing is that I'd also like Administrator to have access to the list of all the Managers and the list of Workers. Also Project should be able to return its Manager and Workers. In C++ to get such list I'm afraid I would have check the class type of each User to filter it out. I feel this is not the right way or is it?

A solution to this could be not creating Manager, neither Worker classes at all but rather adding a User attribute called occupation/designation that would be a string. Then the filtering process would get more straightforward and probably less costly.

If I took this route I'd end up with inaccurate diagram in which multiple Users are aggregated to the Project (or multiple projects) and no way to distinguish between the manager and the workers.

Could somebody please shed some light on this topic and maybe provide some graphical example?

Christophe
  • 68,716
  • 7
  • 72
  • 138
  • 2
    I suggest you need to consider the roles a bit more carefully. For example, consider if it makes sense to view Manager, Worker, and even Administrator as roles that are associated with some functions or capabilities (e.g. administration rights) rather than separate type of user. Also, consider the fact that some users may have multiple roles (e.g. a worker on project A may manage project B and administer project C, etc). So, when building a list of managers of a project, it may may sense extract a list of all users with a role managing that project. – Peter Jun 19 '21 at 10:17
  • I would agree with Peter. Without any more information about your problem domain, I would see Manager, Admin and Worker as "Roles" rather than types of User. – muszeo Jun 25 '21 at 08:33

1 Answers1

0

I would agree with Peter. Without any more information about your problem domain, I would see Manager, Admin and Worker as "Roles" rather than types of User. Something like this:

Users and Roles

muszeo
  • 2,312
  • 9
  • 13