4

I have an enumeration class that has a method in the class body, how do I represent this in a UML class diagram? Is the following a valid way? (It seems reasonable but I couldn't find anyone doing this online.)

enter image description here

2 Answers 2

6

In UML an enumeration is a classifier, so it can have operations.

As strange as it feels, the compartment with the litterals should be below the compartment with the operations (see UML 2.5 specifications, section 10.2.4, emphasis added by me):

The name of the Enumeration is placed in the upper compartment with the keyword «enumeration» above or before the name. A list of EnumerationLiterals may be placed, one to a line, in a compartment named “literals” below the operations compartment. The attributes and operations compartments may be suppressed, and typically are suppressed and empty.

3
  • 1
    @qwerty_so I really like this question, forcing to check the base. I just read that as a classifier an enumeriation could even be specialized, in which case its litterals add to the litterals of the generalisation ^^ This evening I'll definitively go to bed with the feeling of being less dumb than yesterday ;-)
    – Christophe
    Commented Nov 23, 2020 at 16:02
  • Care to know any language that supports that?
    – qwerty_so
    Commented Nov 23, 2020 at 16:07
  • @qwerty_so I'm not aware of a language that inherits the literals, at least in Python and Java that would conflict with type theory invariants. However, languages that implement enums with a class declaration can inherit everything else with the exception of the literals.
    – bad_coder
    Commented Jan 30 at 0:05
2

Yes, that would be ok. An UML Enumeration is a DataType and that can have operations as well. See p. 165 of UML 2.5. And on p. 166:

A compartment listing the Operations is placed below the attribute compartment.

Not the answer you're looking for? Browse other questions tagged or ask your own question.