185

I am modeling a class diagram. An attribute of a class is an enumeration. How do I model this? Normally you do something like this:

- name : string

But how does one do this with an enum?

Peyman Mohamadpour
  • 17,954
  • 24
  • 89
  • 100
Martijn
  • 24,441
  • 60
  • 174
  • 261

3 Answers3

268

They are simply showed like this:

_______________________
|   <<enumeration>>   |
|    DaysOfTheWeek    |
|_____________________|
| Sunday              |
| Monday              |
| Tuesday             |
| ...                 |
|_____________________|

And then just have an association between that and your class.

James B
  • 8,183
  • 4
  • 33
  • 40
  • 17
    Enumerations actually work more like Datatypes than Classes in UML, so typically Associations aren't shown any more than they would be if you declared an attribute to be of type Integer. If your modeling tool has explicit support for enumerations, you should use that and only use the Class + <> stereotype notation as a fallback if necessary. – Tom Morris Feb 02 '12 at 17:11
  • Could you tell where can I find <> stereotype for ArgoUML? – Timofey Jan 22 '16 at 21:42
  • @Tim ArgoUML has first class support for Enumerations, so no need to use the stereotype – Tom Morris Jul 12 '16 at 05:34
  • `<>` actually isn't a stereotype but a keyword. Unfortunately the UML authors did not make any visual differentiation. – qwerty_so May 09 '18 at 08:13
91

If your UML modeling tool has support for specifying an Enumeration, you should use that. It will likely be easier to do and it will give your model stronger semantics. Visually the result will be very similar to a Class with an <<enumeration>> Stereotype, but in the UML metamodel, an Enumeration is actually a separate (meta)type.

+---------------------+
|   <<enumeration>>   |
|    DayOfTheWeek     |
|_____________________|
| Sunday              |
| Monday              |
| Tuesday             |
| ...                 |
+---------------------+

Once it is defined, you can use it as the type of an Attribute just like you would a Datatype or the name one of your own Classes.

+---------------------+
|        Event        |
|_____________________|
| day : DayOfTheWeek  |
| ...                 |
+---------------------+

If you're using ArgoEclipse or ArgoUML, there's a pulldown menu on the toolbar which selects among Datatype, Enumeration, Signal, etc that will allow you to create your own Enumerations. The compartment that normally contains Attributes can then be populated with EnumerationLiterals for the values of your enumeration.

Here's a picture of a slightly different example in ArgoUML: enter image description here

Tom Morris
  • 10,490
  • 32
  • 53
2

Typically you model the enum itself as a class with the enum stereotype

annakata
  • 74,572
  • 17
  • 113
  • 180