简体   繁体   English

UML类图枚举

[英]UML class diagram enum

I am modeling a class diagram. 我正在为类图建模。 An attribute of a class is an enumeration. 类的属性是枚举。 How do I model this? 我该如何建模呢? Normally you do something like this: 通常你做这样的事情:

- name : string

But how does one do this with an enum? 但是如何使用枚举来做到这一点?

They are simply showed like this: 它们只是显示如下:

_______________________
|   <<enumeration>>   |
|    DaysOfTheWeek    |
|_____________________|
| Sunday              |
| Monday              |
| Tuesday             |
| ...                 |
|_____________________|

And then just have an association between that and your class. 然后在它和你的班级之间建立联系。

If your UML modeling tool has support for specifying an Enumeration, you should use that. 如果您的UML建模工具支持指定枚举,则应使用它。 It will likely be easier to do and it will give your model stronger semantics. 它可能会更容易做,它会给你的模型更强的语义。 Visually the result will be very similar to a Class with an <<enumeration>> Stereotype, but in the UML metamodel, an Enumeration is actually a separate (meta)type. 在视觉上,结果将与具有<<enumeration>> Stereotype的类非常相似,但在UML元模型中,Enumeration实际上是一个单独的(元)类型。

+---------------------+
|   <<enumeration>>   |
|    DayOfTheWeek     |
|_____________________|
| Sunday              |
| Monday              |
| Tuesday             |
| ...                 |
+---------------------+

Once it is defined, you can use it as the type of an Attribute just like you would a Datatype or the name one of your own Classes. 定义之后,您可以将它用作属性的类型,就像使用数据类型或您自己的类的名称一样。

+---------------------+
|        Event        |
|_____________________|
| day : DayOfTheWeek  |
| ...                 |
+---------------------+

If you're using ArgoEclipse or ArgoUML, there's a pulldown menu on the toolbar which selects among Datatype, Enumeration, Signal, etc that will allow you to create your own Enumerations. 如果您使用的是ArgoEclipse或ArgoUML,工具栏上会有一个下拉菜单,可以在数据类型,枚举,信号等中进行选择,以便您创建自己的枚举。 The compartment that normally contains Attributes can then be populated with EnumerationLiterals for the values of your enumeration. 然后,通常包含属性的隔离专区可以使用EnumerationLiterals填充枚举值。

Here's a picture of a slightly different example in ArgoUML: 以下是ArgoUML中略有不同的示例: 在此输入图像描述

通常,您将枚举本身建模为具有enum型的类

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM