如何用 UML class 图中的方法表示枚举 classes

How to represent enumeration classes with methods in UML class diagram

我有一个枚举 class,它在 class 主体中有一个方法,我如何在 UML class 图中表示它?以下是有效的方法吗? (这似乎是合理的,但我在网上找不到任何人这样做。)

在 UML 中,枚举是一个分类器,因此它可以有操作。

虽然感觉很奇怪,但带有文字的隔间应该低于带有操作的隔间(请参阅 UML 2.5 规范,第 10.2.4 节,重点由我添加) :

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.

是的,没关系。 UML 枚举是一种数据类型,也可以有操作。见第UML 2.5 的 165。并在第166:

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