问题
In a UML class diagram, how would I model a tutor can work multiple days of the week without knowing specifically? In my current solution: 1 or more tutors work on 1 or more days of the week.
回答1:
Since the list of days when Tutor work is only an attribute and doesn't seem to have any specific structure to build a class around it, it should rather be an inline attribute with type DaysOfTheWeek
and multiplicity 1..7
. Also since you can't work twice at the same day you should add unique
constraint.
Your argument (within the class Tutor
) should look like that:
-workingDays : DaysOfTheWeek [1..7] {unique}
The multiplicity on Tutor side in your diagram suggests you have at least one Tutor for each possible working day (enumeration value). If this is true you can add this as a class constraint then.
For traceability reasons you can add dependency (dashed line with open arrow) from Tutor
to DaysOfTheWeek
, but that's not necessary.
If you have a reason to build a dedicated class, your diagram can look like this
I'm sorry, for some reason my tool doesn't export the stereotype even though I've placed it. DaysOfTheWeek should have the Enumeration but it was lost in the export.
A general side remark: a class has to have a name. It can't be just a stereotype.
回答2:
I would simply add a property like this:
According to the specs (p. 34):
来源:https://stackoverflow.com/questions/48897990/uml-class-diagram-modelling-with-enumeration