I'm trying to draw an class diagram for my project management software describing the following. It contains the following classes:
Project
- software projects ProjectManager
- he/she who manage the project Employee
- people who are engage in project work and the following relationships/associations:
a project manager may have to manage more than one project, while a project can only be managed by one project manager
a project manager can assign an employee to a project that he/she manages
For the above associations I created this class diagram:
ProjectManager
and Project
) Your question is close to the example above that we have been using for many years in our UML Trainings at my company BITPlan.
In this example there is a ProjectAssignment class and the rule is that for each point in time there may be only one ProjectAssignment with "responsible=true". The Employee with this ProjectAssignment is the ProjectManager. This style can also be applied when subproject come into play and you'd like to model a whole hierarchy of managers that may vary over time.
Personally I think it is quite often much better to state such restrictions in prose in the documentation of a model instead of trying to show it in the structure using inheritance and cardinalities.
You just add an operation to Project
called assignEmployee
which will add the employee to its list of assigned employees:
It's unclear how an employee can be assigned, whether to just one or multiple projects. Also you will likely need a de-assign operation.
Of course you can also use an association class like suggested by @WolfgangFahl.
A more general approach to model your problem is using an object type Person
(or Employee
) both for project managers and employees. This would express that project managers are also employees and can be assigned to some projects as managers while they are assigned to other projects as ordinary employees.
In such an approach, you would have the two classes Employee
and Project
with two associations between them:
Employee
-works-for- Project
(or better use a role name like worker
at the association end). Employee
-is-manager-of- Project
, where manager
is the role name. If you really need to model/record the assignment of employees to projects by project managers, then you need to replace the first association ( Employee
-works-for- Project
) with a ternary association Employee
-is-assigned-to- Project
-by- Employee
-as- assigner
where the latter employee (the assigner) is required to be the manager of the assigned project. This condition can be captured with a corresponding invariant attached to the Employee
class.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.