带或不带箭头的UML聚合 [英] UML Aggregation with and without arrow head

查看:97
本文介绍了带或不带箭头的UML聚合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直认为UML聚合定义为路径开头的黑色(实心)菱形,而结尾处没有箭头:

  | -------- | | -------- | 
| :MyA |<> ------ | :MyB |
| -------- | | -------- |

今天我遇到了类似<> ----的符号-> (在右端带有明确的箭头)。因此,我在UML 2.4规范中进行了查找,并实际上找到了这两个版本的参考。



我最喜欢的参考:Craig Larman的 UML and Patterns em>仅提及第一个没有箭头的版本。在UML规范中,我发现了有关可导航结束的通知,但是我不确定这是否相关以及有什么区别?



可以有人会对此做更详尽的解释,并举例说明每个版本的使用吗?

解决方案

任何关联结束都可以指定为导航箭头。但是,UML的可导航性概念没有确切的含义,人们将其与另一端的类拥有关联端的概念相混淆。类的 关联端所有权概念意味着关联端对应于该类的引用属性。仅在去年的新UML版本2.5中对此问题进行了澄清,该版本为关联最终所有权引入了新的可视化表示法,如。这很可能是您所遇到的预期含义,即



有关更多说明,请参见教程



评论的其他答案:如果您的类模型指定了所有关联端的所有权,并且您的类图显示了它们,并且没有所有权点(也没有可导航性箭头),如,则关联端由关联本身拥有。由于我们在MyA端都没有所有权点,因此两端都由复合关联拥有。就要编写/生成的代码而言,这意味着复合关联不能通过MyA或MyB中的引用属性来实现,而必须借助单独的类来实现,例如 MyA-has- MyB,它具有两个引用属性,可同时引用任何组合链接的聚集和组件,如以下类矩形:




I always thought that the UML aggregate is defined as a black (filled) diamond at the beginning of a path and no arrow head that the end:

|--------|        |--------|
| :MyA   |<>------| :MyB   |
|--------|        |--------|

Today I came across a notation like <>-----> (with an explicit arrow head on the right end). So I looked it up in the UML 2.4 specification and actually found references for both versions.

My favourite reference: "UML and Patterns" by Craig Larman only mentions the first version without the arrow. In the UML specification I found a notice about navigable ends, but I am not sure if this is related and if whats the difference?

Could someone explain this more thoroughly and give an example for the use of each version?

解决方案

Any association end can be designated to be "navigable" with the help of a navigability arrow. However, UML's notion of "navigability" does not have a precise meaning and people confused it with the concept of an association end being owned by the class at the other end. This concept of association end ownership by a class means that the association end corresponds to a reference property of that class. This issue has only been clarified in last year's new UML version 2.5, which has introduced a new visual notation for association end ownership, a "dot" as in . This is most likely the intended meaning of what you came across, namely , and what it really means is the following reference property:

For more explanation see this tutorial.

Additional answer to the comment: If your class model specifies the ownership of all association ends, and your class diagram displays them, and there is no ownership dot (nor a navigability arrow), as in , then, according to UML 2.5, the association end is "owned" by the association itself. Since we do neither have an ownership dot at the MyA end, both ends are "owned" by the composite association. In terms of the code to write/generate, this would mean that the composite association is not implemented by means of reference properties in either MyA or MyB, but has to be implemented with the help of a separate class, say "MyA-has-MyB", which has two reference properties for referencing both the aggregate and the component of any composition link, as in the following class rectangle:

这篇关于带或不带箭头的UML聚合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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