在 UML 中,属性是关联端,可以由关联或参与的分类器(通常是类)拥有。当属性由类拥有时,它称为属性。属性。例如,属性 Book::author
可以获得以下符号之一(其中应在右侧图的作者关联端绘制一个点):
该属性可用于约束表达式如:self.author
或 mybook.author->count()
这对于二元关联来说很简单。但我怀疑这如何与三元(或更一般的 N 元)关联一起使用,例如:
声明 Project
将具有属性是否正确participant
和属性 role
因为它们是关联的相反成员端?
考虑到参与者和角色不是独立的,如何在约束中利用它们的相关性,例如引用具有给定角色的贡献者,或者引用集合(participant,role)
-元组将其 ->count()
限制为小于 10?
In the UML, a Property is an association end and can be owned either by the association or by a participating Classifier, which is typically a class. When a Property is owned by a class, it's called an attribute. For example, an attribute Book::author
could get one of the following notations (where a dot should be drawn at the author association end of the right-hand side diagram):
The attribute could be used in constraint expressions like: self.author
or mybook.author->count()
This is straightforward for binary associations. But I have doubts how this works with ternary (or more generally N-ary) associations, for example:
Is it correct to state that Project
would have an attribute participant
and an attribute role
since these are the opposite member ends of the association?
And considering that participant
and role
are not independent, how to make use of their correlation in constraints, for example to refer to the contributors having a given role, or to the set of (participant,role)
-tuples to constrain its ->count()
to less than 10?
发布评论
评论(2)
对于 n 元关联,所有端都必须由关联拥有,因此它们不是属性。
第 11.8.1.8 节中有一个约束,因此,它很清楚:
For n-ary associations all ends must be owned by the association and thus, they are not attributes.
There is a constraint in section 11.8.1.8, so, it is as clear as it gets:
当然,在您的示例中,诸如
Project::participant
或Project::role
之类的属性对于表示三元链接没有任何意义。UML 规范(在 11.4.3.1 类中)指出
他们没有提到属性作为非二元关联的末端的可能性。
正如 @Christophe 所指出的,在 11.5.4(第 202 页)中,他们说
这里重要的概念是“另一端”,在规范的其他陈述中也称为“相反端”。这意味着关联必须有一个唯一的另一端。
因此,由于属性是相对端的分类器拥有的关联端(= 属性),因此它们只能是二元关联的端部。
这意味着对于 n 元关联,参与类不能拥有任何端,因此不能具有(引用)属性,例如
Project::participant
。另外,使用常识:诸如
Project::participant
(或更好:Project::participants
)这样的属性的可能含义是什么?它可能旨在表示参与三元关联Project
-Contributor
-Contributor
对象的集合>角色。这可以使用 OCL 表达式定义为派生属性。但它不允许表示/实现/重构三元关联。在 OOP 中,您可以拥有类似
Project::contributorByRole
的属性,其值将按Contributor
和Role
的笛卡尔积排序。 。这样的属性代表/实现了三元关联。但是,据我所知,UML 没有定义笛卡尔积类型,因此不支持此类元组值属性。Of course, in your example, attributes like
Project::participant
orProject::role
do not make any sense for representing ternary links.The UML spec (in 11.4.3.1 Classes) states that
They don't mention the possibility of attributes as ends of non-binary Associations.
In 11.5.4 (page 202), as pointed out by @Christophe, they say
The important concept here is "the other end", which is also called "the opposite end" in other statements of the spec. It implies that there must be a unique other end of the association.
Consequently, since Attributes are association ends (= Properties) owned by the Classifier at the opposite end, they can only be the ends of a binary association.
This implies that for n-ary associations, the participating classes cannot own any end and can therefore not have (reference) attributes like
Project::participant
.Also, using common sense: what would be the possible meaning of an attribute like
Project::participant
(or better:Project::participants
)? It could be intended to represent the collection of allContributor
objects that participate in an instance/link of the ternary associationProject
-Contributor
-Role
. This could be defined as a derived attribute using an OCL expression. But it does not allow to represent/implement/reconstruct the ternary association.In OOP, you could have a property like
Project::contributorByRole
the values of which would be ordered pairs from the Cartesian Product ofContributor
andRole
. Such a property represents/implements the ternary association. But, afaik, UML does not define Cartesian Product types and does, therefore, not support such tuple-valued properties.