5h. UML Elements - Enumeration
Let's talk about more advanced types and dive into DataTypes. We'll start by talking about Enumerations.
What is a DataType?
Before talking about Enumerations, we should talk about DataTypes.
"A DataType is a kind of Classifier. DataType differs from Class in that instances of a DataType are identified only by their value. All instances of a DataType with the same value are considered to be equal instances."
DataTypes are very similar to Classes. They have attributes and operations and they are able to be instantiated. The only difference is that instances created from a DataType is identified by it's values.
What is an Enumerations?
"Enumeration is a kind of DataType. Each value of an Enumeration corresponds to one of its user-defined EnumerationLiterals."
An Enumeration is used as a way to constrain a "type" of a Property or another typed element to a limited list of values. These values are known as EnumerationLiterals. An Enumeration isn't meant to be instantiated. Instead, the instances (or values) which are EnumerationLiterals, are pre-defined and read-only.
Enumerations are shown the same way that a Class is shown in UML Class Diagrams, except that it has an "«enumeration»" keyword above the name.

EnumerationLiteral
As mentioned previously, An EnumerationLiteral is considered an instance of the Enumeration. But, unlike a Class, the Enumeration has access to them. The Enumeration calls these it's "ownedLiteral"s. They are the values that can get set to properties of other instances where that Property's type is that Enumeration.
EnumerationLiteral's are distinguished by their "name". So different EnumerationLiterals for a particular Enumeration must have names that are distinct.
An EnumerationLiteral is also considered real-only and isn't able to be updated.
Comparison to Object-Oriented Programming Languages
Enumerations are used in many object-oriented programming languages. Many languages use the "enum" keyword to create an Enumeration and othes use "Enum". The values of enums are similar to EnumerationLiterals.
How do you know when to define a new Enumeration?
The key for defining a new Enumeration is to determine how the set of possible values a Property may possibly be set to. When you determine there is a finite set of values that you would like to be assigned to a Property, you should consider using an Enumeration. For example, when you know that there is a list of only 4 values that should be assigned to a Property of a Class, you may consider using an "Enumeration" for that Property's type.
If the Property should have a finite set of values where there are only 2 values, it is usually best to use a Boolean, but it is up to the modeler to define. However, if there are 3 or more finite values, it is beneficial to use an Enumeration that has 3 EnumerationLiterals.
Abstract Syntax
To illustrate what an Enumeration is, UML provides abstract syntax which we have recreated in UML Class Diagrams.


