So, I have an enumeration that is as follows:
+---------+
|TypeCours|
| Enum |
+---------+
| TD |
| TP |
| CM |
+---------+
and for another class (Module), I need to modelize the fact that for each of those enum values, I require an int value.
So that every instance of Module has for example (TD, 15), (CM, 30) and (TP, 40) to its disposal. Where 15, 30 and 40 are specific to the instance.
I’ve been advised to use an enum since it should allow easier evolution (like adding a value to the enum type) compared to just having 3 int fields doing the same job.
My question is, what kind of association do I need between my class Module, the enum TypeCours (and potentially a third class?) to modelize that need ?
Interesting questions. I would create a new class called
TypeCoursValuewhich has the value ofTypeCourseand theintvalue. Then you must add a relation betweenModuleandTypeCoursValue.The interesting part is how to model the constraint that specifies that for every value of
TypeCoursyou need an instance of this new class. I don’t know of any UML notation to do this other than comments, so I would add a comment to the relation “there must be one instance ofTypeCroursValuefor every value ofTypeCourse“.