UML Enumeration (in UML Class Diagram)
What is Enumeration in UML Class Diagram?
A UML enumeration represents a complete list of all values that a given type may acquire. An enumeration is used as a type of attribute, operation, and operation parameters. Enums may be used in a flag mode to support bitwise combinations of particular values.
An enumeration is depicted as a rectangular box with a name and a line-separated list of items. The enumeration element is decorated with the «enumeration» stereotype. The stereotype caption allows us easy to differ from other element types (e.g. classes).
An enumeration is represented by its values. A meaningful enumeration should contain two and more values.
UML Enumeration Literal
An item of enumeration is also called enumeration literal. It is represented by its name. Optionally, a numeric or other type value for the literal may be defined.
How to Add Values to Enum
In the diagram editor, you can add other enumeration items using the context bar. First, create a new enumeration or select an existing one. Then click on the Add Item button in the context bar (usually placed below the selected enumeration). A new item will be added to the enumeration and you can enter its name.
An enumeration connects to a class using a UML association relationship. The relationship says whether an attribute, operation, or operation parameter within a connected classifier uses the enumeration as its type. Association from a classifier to an enumeration may be omitted. UML enumeration can be used simply as a data type for attributes, operations, and parameters without an association line in the diagram.
UML Enum Association
An enum may be associated with a class or a class field (attribute, operation) in our UML tool. If you drag (using the right mouse button) the enumeration and drop it over an attribute, it will be set as its type.
Enumeration in UML Class
An enum can be defined within a UML class. This may be modeled using containment relationships in the UML class diagram.
Enumeration Items with Defined Values
Specific values can be assigned to enumeration items. The value of the enumeration item is displayed after the item name and the equals sign =. You can enter the specific value to an enumeration item very easily - just edit the item in the diagram editor and append = value after the item name.
Another way is to open the Properties dialog (right-click on the desired enumeration and select Properties from the context menu) and switch to the Items tab. It offers a tabular editor with two columns - Name and Value. You can edit the particular enumeration items there.
The following example shows how to represent an enum in class diagrams. Check out our UML class diagram example with an enumeration element:
Create Enumeration in Software Ideas Modeler
The UML tool Software Ideas Modeler allows you to create and use enumerations in your diagrams intuitively.