关联类唯一性 [英] Association Class Uniqueness

查看:40
本文介绍了关联类唯一性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很难理解 UML 2.5 规范中解释的关联类的概念.最让我困惑的是摘自第 199 页的以下句子:

I have a hard time understanding the concept of association class as explained in UML 2.5 specification. The thing that confuses me the most is the following sentence taken from page 199:

注意.即使 AssociationClass 的所有端都具有 isUnique=true,也可能有多个实例关联端类的同一组实例.

NOTE. Even when all ends of the AssociationClass have isUnique=true, it is possible to have several instances associating the same set of instances of the end Classes.

如此处所述:https://issues.omg.org/issues/UMLR-757 这一句话似乎削弱了这个概念的用处.同时,它使得几乎所有解释在 UML 规范 2.5 版本之前编写的概念的文本都过时了——例如,参见这里的讨论:UML 关联类 - 澄清

As noted here: https://issues.omg.org/issues/UMLR-757 this single sentence seems to undermine the usefulness of the concept. At the same time, it makes pretty much every text explaining the concept written before 2.5 version of the UML spec obsolete – see for example the discussion here: UML association class - clarifying

但这实际上如何在概念上起作用?假设关联类的所有端都有isUn​​ique=true,当isUn​​ique时,怎么会有多个关联类的实例关联同一组端类的实例会员端的属性是否明确禁止此类链接的存在?

But how can this actually work conceptually? Assuming all ends of the association class have isUnique=true, how can one have more than one instance of association class associating the same set of instances of the end classes, when isUnique property of member ends clearly forbids existence of such links?

我一直认为关联类只是具有额外属性和/或操作的常规关联.这种解释现在似乎无效.那么究竟什么是关联类呢?它如何具有独立于协会成员端的唯一性?似乎有一些不言而喻的多重性潜伏在某处(唯一性是不相关的属性,如果最大多重性高于 1),但我不知道在哪里.

I’ve always thought that an association class is just a regular association with extra attributes and/or operations. That interpretation seems to invalid now. So what exactly is association class? How can it have uniqueness independent from that of association member ends? There seem to be some unspoken multiplicity lurking somewhere (uniqueness is irrelevant property without maximum multiplicity higher than 1), but I can't figure out where.

推荐答案

简而言之

确实,这不是非常清楚,值得更好的解释.简而言之:这只是为关联类定义的双重语义缺乏集成的结果.

In very short

Indeed, this is not super-clear and would deserve a better explanation. To make it short: it’s just a consequence of the lack of integration in the dual semantics defined for the association class.

根据 UML 2.5.1 第 11.5.3.1 节,第 197 页:

According to UML 2.5.1 section 11.5.3.1, page 197:

当关联的一个或多个端具有 isUnique=false 时,可能有多个链接关联同一组实例.

When one or more ends of the Association have isUnique=false, it is possible to have several links associating the same set of instances.

我们可以使用合乎逻辑的对立推断:

We can deduct using logical contraposition that:

如果不可能有多个链接关联同一组实例,则关联的所有端都具有 isUnique=true.

If it is not possible to have several links associating the same set of instances, all ends of the association have isUnique=true.

所以我们希望这也适用于关联类,因为关联类也是关联.

So we'd expect this to apply to an assocation class as well, since the association class is also an association.

根据 UML 2.5.1 第 11.5.3.2 节:

According to UML 2.5.1 section 11.5.3.2:

AssociationClass是Association和Class,并且保留两者的静态和动态语义.

An AssociationClass is both an Association and a Class, and preserves the static and dynamic semantics of both.

因此,关联类不仅仅是具有额外属性的关联".如果真的那么简单,那么关联类完全可以是关联的泛化:专门化的关联只会继承额外的属性.但这是明确禁止的第199页:

So, an association class is not just "an association with extra attributes". If it were that simple, the association class could perfectly be a generalization of an association: the specialized association would just inherit the extra attributes. But this is explicitly prohibited page 199:

AssociationClass 不能是 Association 的泛化或班级.

An AssociationClass cannot be a generalization of an Association or a Class.

因为对类的任何特化都会失去关联语义,而对关联的任何特化都会失去类语义.

because any specialization into a class would loose the association semantics, and any specialization into an association would loose the class semantics.

这种二元性是我们问题的根源.

And this duality, is the cause of our issue.

根据 UML 第 11.5.3.2 节,第 199 页(格式来自我):

According to UML section 11.5.3.2, page 199 (formatting from me):

AssociationClass 的实例具有将 AssociationClass 的实例化表示为一种关联的链接表示实例化的对象的特征 将 AssociationClass 作为一种类.

An instance of an AssociationClass has the characteristics both of a link representing an instantiation of the AssociationClass as a kind of Association, AND of an object representing an instantiation of the AssociationClass as a kind of Class.

如果所有关联结束isUn​​ique=true,则保证关联的实例是唯一的.但是请注意,关联仅与由关联结束组成的元组有关:

If isUnique=true for all association ends, the instances of the association are guaranteed to be unique. Remind however that the association is only about tuples made out of the association ends:

Association 声明类型符合或实现关联类型的实例之间可以存在链接.链接是一个元组,每个成员关联一个值,其中每个值是一个实例,其类型符合或实现了末尾的类型.

An Association declares that there can be links between instances whose types conform to or implement the associated types. A link is a tuple with one value for each memberEnd of the Association, where each value is an instance whose type conforms to or implements the type at the end.

但是,规范中没有任何内容要求表示关联实例化的类实例化(对象)必须是唯一的.

However, nothing in the specs requires that the class instantiation (object) representing the association instantiation needs to be unique.

想象一下,例如,我们在 ABab 是这些类的实例.假设关联端具有 isUn​​ique=true.这意味着只有一个元组 (a,b) 因为关联被保证是唯一的.

Imagine for example, that we have an association class between class A and class B, and a and b are instances of these classes. Imagine that the association ends have isUnique=true. This means that there can be only one tuple (a,b) since the association is guaranteed to be unique.

设P为关联类的一个属性,设(a,b,p1)(a,b,p2)为该类的两个实例在协会类.类不知道关联端:从类的角度来看,没有单一性要求.从关联的角度来看,我们只有一个元组 (a,b) ,所以也可以.

Let P be a property of the association class, and let (a,b,p1) and (a,b,p2) be two instances of the class in the association-class. The class knows no association-ends: from the point of view of the class, there is no unicity requirement. And from the point of view of the association, we have only one tuple (a,b) , so it's ok as well.

NOTE 只是解释了这种(不幸和模棱两可的)情况是可能的.

The NOTE just explains that this (unfortunate and ambiguous) situation is possible.

形式上,没有矛盾.这是关联类定义方式的结果:同时一个类和一个关联,没有进一步定义各自实例之间的关系.

Formally, there is no contradiction. This is the result of the way the association class is defined: a class and an association at the same time, without further defining the relationship between the respective instances.

但这会在具有非唯一目的的关联的语义方面产生一些问题:

But this creates some issues in regard of the semantics of associations having non-unique ends:

当关联的一个或多个端具有 isUn​​ique=false 时,可能有多个链接关联同一组实例.在这种情况下,链接除了其最终值之外还带有一个额外的标识符.

When one or more ends of the Association have isUnique=false, it is possible to have several links associating the same set of instances. In such a case, links carry an additional identifier apart from their end values.

更准确地说,这使得具有唯一目的的关联类毫无用处,因为可以通过非唯一目的实现相同的结果:

More precisely, this makes the the association-class with unique ends useless, since the same result can be achieved with non-unique ends:

  • 对于具有非唯一端的简单关联,您可以有重复项,即多个链接将关联端的相同实例相关联,并使用附加标识符进行区分.
  • 对于具有唯一端的关联类,根据注释,您可以有重复项,即多个对象(类实例)对应于由唯一关联端(关联实例)组成的链接.
  • 对于具有非唯一端的关联类,您可以有重复项,即多个对象实例对应于同一组成员端.如果您将其解释为关联关联端的相同实例的多个链接,每个关联与单个对象关联,或者,如果您将其解释为关联关联端的唯一实例集的一个链接,那么这没有区别每个都与多个对象实例相关联.

恕我直言,这很不幸:

  • 它与我们的心智模型不匹配,在该模型中,所有关联端都具有 isUn​​ique=true 的关联类应该具有该类的唯一对象实例,以实现唯一的组合关联端.这显然违背了最小惊讶原则:我从拒绝开始,我花了一段时间才接受这一点,因为它与实现关联类的传统方式非常不同.
  • 两种不同的模型,一种具有独特的关联结束,另一种实际上可以表达相同的情况.
  • it does not match our mental model in which an association class with all association ends having isUnique=true should have a unique object instance of the class for a unique combination association ends. This clearly goes against the principle of least astonishment: I started with deny and it took me a while to accept this, since it was so terribly different from the traditional ways to implement association classes.
  • two different models, one with unique association ends, and one without could in fact express the same situation.

这个问题的一个简单解决方案是需要一个唯一的类实例(对应于关联类的对象)来对应一个唯一关联关联端的链接.这样,唯一的关联端就意味着唯一的关联对象,而不需要对 UML 规范进行其他更改.

A simple solution to this issue would be to require a unique class instance (object corresponding to the association class) to correspond to a link that uniquely associates association ends. In that way, unique association ends would imply unique association object, without requiring other changes to the UML specs.

这篇关于关联类唯一性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆