多重关系中的UML关联类 [英] UML association class in multiple relations

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

问题描述

我正在用 UML 制作类图,但找不到有关此主题的信息.我可以在多个协会课程中开设一个课程吗?这是一个例子:

Message 应该是用户和组之间的关联类,也是用户和频道之间的关联类.这是允许的还是有其他方法可以做到这一点?谢谢!

解决方案

什么是关联类?

在查看关联类的图形符号时,我们可能会误以为关联类只是附加到关联的类.

但关联类实际上是一个关联,同时也是一个类:

<块引用>

UML 2.5.1/第 11.5.3.2 节:AssociationClass 是对具有自己的一组功能的 Association 的声明.AssociationClass既是Association又是Class,同时保留了两者的静态语义和动态语义.

所以在建模语义上,除了表示法之外,不能把关联类和对应的关联分开.如果您还不相信,请看规格中的下一句:

<块引用>

AssociationClass 描述了一组对象,每个对象共享 AssociationClass 作为一类类所包含的相同的特征、约束和语义规范,并对应于一个唯一的链接,将 AssociationClass 实例化为一种协会.

(链接是关联的实例,对应于具有每个成员关联的一个值"的元组)

关联类二元性的后果是什么?

结果是相同的关联类不能存在于多种风格中,而每种风格都会关联不同的类集.

虽然符号中没有任何内容阻止您添加虚线以看似附加"同一个类到两个不同的关联

  1. 忘记关联类.使 Message 成为与 User 相关联的普通类.它还与 GroupChanel 相关联.如有必要,在这两个关联之间添加一个 {xor} 约束(如果它们是互斥的).

事实上,您目前仅与 Group 而非 Channel 建立多对多关联,这表明存在一些显着差异并且会赞成(2) 而不是 (1).

不相关:您当前的模型中有什么奇怪的东西?

无论关联类主题如何,您当前的模型都提出了一些关于与 Group 的多对多关联的问题:

  • 您的意思是多个用户可以向多个群组发送相同的消息吗?
  • 还是您的意思是一个用户可以向一个群组发送消息并且该群组由多个用户组成?

在后一种情况下,您应该选择 2 个不同的关联:一个用于发送关联,一个用于群组成员关联(参见上图中的红色关联).

I'm making a class diagram in UML, and I can't find information about this topic. Can I have a class in several associations-classes? here's an example:

Message should be an association class between user and group, but also between user and channel. Is this allowed or is there any other way to do this? thank you!

解决方案

What is an association class?

When looking at the graphical notation of an association class, we could be mislead to think that an association-class is simply a class that is attached to an association.

But the association class is in reality an association AND AT THE SAME TIME a class:

UML 2.5.1 / Section 11.5.3.2: An AssociationClass is a declaration of an Association that has a set of Features of its own. An AssociationClass is both an Association and a Class, and preserves the static and dynamic semantics of both.

So in the modelling semantic, beyond the notation, you cannot separate the association class from the corresponding association. If you're not convinced yet, here the next sentence in the specifications:

An AssociationClass describes a set of objects that each share the same specifications of Features, Constraints, and semantics entailed by the AssociationClass as a kind of Class, and correspond to a unique link instantiating the AssociationClass as a kind of Association.

(links are instances of an association and correspond to tuples with "one value for each memberEnd of the Association")

What are the consequence of the association-class duality?

The consequence is that the same association-class cannot exist in multiple flavors that would each associate different sets of classes.

While nothing in the notation prevents you from adding a doted line to seemngly "attach" the same class to two different associations as Bruno explains, this notation would not correspond to a valid UML semantic.

Alternatives

Your question underlines an interesting design issue. And fortunately, there are plenty of ways to solve it. For example:

  1. User class is associated to an abstract Destination class. Message would be the association-class. Destination would be specialized into Group and Chanel that would both inherit the association (no need to duplicate the association graphically). (Edit: as underlined by Axel Scheithauer in the comments, the association and the association class being one and the same, they must have the same name)

  1. Forget about the association class. Make Message a normal class, associated with User. Associate it also with Group and Chanel. If necessary, add an {xor} constraint between these two associations if they are mutually exclusive.

The fact that you currently have a many-to-many association only with Group and not with Channel, suggest that there are some significant differences and would speak in favor of (2) rather than (1).

Not related: Something weird in your current model?

Regardless of the association-classtopic, you current model raises some questions regarding the many-to-many association with Group:

  • do you meant that several users can send a same message to several groups?
  • or do you mean that a user can send messages to a group and the group is made of several users?

In the latter case, you should go for 2 distinct associations: one for the sending association, and one for the group membership association (see the red association in the diagrams above).

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

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