The Object Constraint Language: Getting Your Models Ready for MDA (2nd Edition)

An enumeration type is a special user -defined type often used as a type for attributes. It is defined within the UML class diagram by using the enumeration stereotype, as shown in Figure 8-4. The values defined in the enumeration can be used as values within an OCL expression. The notation to indicate one of the enumeration values in an OCL expression is the enumeration type name , two colons, followed by the enumeration value identifier. Note that the previous version of OCL used a different notation.

Figure 8-4. Customer class with enumeration

In Figure 8-4, the Customer class is shown again. Now we have changed the attribute isMale to an attribute gender . The following invariant states that male Customer s must be approached using the title 'Mr.' .

context Customer inv : gender = Gender::male implies title = 'Mr.'

The only operators available on enumeration values are the equality and inequality operators. They are denoted by = and <>, respectively.

Категории