UML:自定义数据类型作为 classes 中的属性/允许向 class 添加属性时
UML: Self-defined data types as attributes in classes / when adding an attribute to a class is allowed
有人问过类似的问题,但这并不能完全解决我的问题:
Object as data attribute of class in Class diagram UML
When to use an attribute (property) instead of an association/aggregation/composition when drawing a UML
我对老师的以下陈述有疑问:
- "You can only have in-built or custom-defined data types, as types of attributes in your classes. For other attributes multiplicity defines quantity and whether it is obligatory."(很公平)
让我们假设以下描述:
[...]每个操作都包含一系列要在所需质量级别上执行的任务 - 对于每个任务,都有一个从该任务的可用质量级别列表中选择的关联质量级别。[.. .](操作也包含许多其他属性)。
现在我画了下面"class diagram":
问题:
我可以将自定义数据类型作为我的 class 图表的一部分(作为 class),还是可以将它们仅用作其他 [=58] 中的属性=]es?
如果这些数据类型只能用作属性,那么我不知道如何通过将此属性添加到 class - 根据我的老师的说法 - 这是不允许的 - 因为那时我将拥有一个既不是内置类型也不是自定义类型的类型的集合作为属性。
据我所知,向 class 添加一个属性并指定此集合是有序的,这是标记此类 属性 的唯一方法,并且无法通过多重性实现。
有人可以解释一下什么是正确的表示法吗?
您可以根据需要在图表上设置任意数量的自定义 Datatype
,但请注意:Datatype
和 Class
[= 之间存在差异23=]
UML 允许同时使用 Classes
和 Datatypes
作为您的 Attribute
.
的类型
在 UML 中,Attributes
和 Associations
通常可以互换。两者的定义特征在 Property
中定义,其中包括多重性和其他约束,例如 {ordered}
但是,您的老师可能也提到了使用中的最佳实践。对 Datatypes
的关系使用属性,对 Classes
的关系使用关联是非常明智的。有关此的更多信息,请参阅 UML Best Practice: Attribute or Association
有人问过类似的问题,但这并不能完全解决我的问题:
Object as data attribute of class in Class diagram UML
When to use an attribute (property) instead of an association/aggregation/composition when drawing a UML
我对老师的以下陈述有疑问:
- "You can only have in-built or custom-defined data types, as types of attributes in your classes. For other attributes multiplicity defines quantity and whether it is obligatory."(很公平)
让我们假设以下描述:
[...]每个操作都包含一系列要在所需质量级别上执行的任务 - 对于每个任务,都有一个从该任务的可用质量级别列表中选择的关联质量级别。[.. .](操作也包含许多其他属性)。
现在我画了下面"class diagram":
问题:
我可以将自定义数据类型作为我的 class 图表的一部分(作为 class),还是可以将它们仅用作其他 [=58] 中的属性=]es?
如果这些数据类型只能用作属性,那么我不知道如何通过将此属性添加到 class - 根据我的老师的说法 - 这是不允许的 - 因为那时我将拥有一个既不是内置类型也不是自定义类型的类型的集合作为属性。
据我所知,向 class 添加一个属性并指定此集合是有序的,这是标记此类 属性 的唯一方法,并且无法通过多重性实现。
有人可以解释一下什么是正确的表示法吗?
您可以根据需要在图表上设置任意数量的自定义
Datatype
,但请注意:Datatype
和Class
[= 之间存在差异23=]UML 允许同时使用
Classes
和Datatypes
作为您的Attribute
. 的类型
在 UML 中,
Attributes
和Associations
通常可以互换。两者的定义特征在Property
中定义,其中包括多重性和其他约束,例如{ordered}
但是,您的老师可能也提到了使用中的最佳实践。对 Datatypes
的关系使用属性,对 Classes
的关系使用关联是非常明智的。有关此的更多信息,请参阅 UML Best Practice: Attribute or Association