三元关联相关的属性

发布于 2025-01-10 06:34:01 字数 794 浏览 1 评论 0 原文

在 UML 中,属性是关联端,可以由关联或参与的分类器(通常是类)拥有。当属性由类拥有时,它称为属性。属性。例如,属性 Book::author 可以获得以下符号之一(其中应在右侧图的作者关联端绘制一个点):

在此处输入图像描述

该属性可用于约束表达式如:self.authormybook.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):

enter image description here

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:

enter image description here

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

情域 2025-01-17 06:34:01

对于 n 元关联,所有端都必须由关联拥有,因此它们不是属性。

第 11.8.1.8 节中有一个约束,因此,它很清楚:

association_ends

具有两个以上端点的关联的端点必须是
归协会本身所有。

inv:memberEnd->size()> 2 意味着ownedEnd->includesAll(memberEnd)

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:

association_ends

Ends of Associations with more than two ends must be
owned by the Association itself.

inv: memberEnd->size() > 2 implies ownedEnd->includesAll(memberEnd)

柏拉图鍀咏恒 2025-01-17 06:34:01

当然,在您的示例中,诸如 Project::participantProject::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 的属性,其值将按 ContributorRole 的笛卡尔积排序。 。这样的属性代表/实现了三元关联。但是,据我所知,UML 没有定义笛卡尔积类型,因此不支持此类元组值属性。

Of course, in your example, attributes like Project::participant or Project::role do not make any sense for representing ternary links.

The UML spec (in 11.4.3.1 Classes) states that

Attributes of a Class are Properties that are owned by the Class. Some of these attributes may represent the ends of binary Associations.

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

Ownership of Association ends by an associated Classifier may be indicated graphically by a small filled circle, which (...) we will term a dot.(...) The dot shows that the model includes a Property of the type (...). This Property is owned by the Classifier at the other end.

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 all Contributor objects that participate in an instance/link of the ternary association Project-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 of Contributor and Role. 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文