指针/引用数据成员是否指示UML中的关联或聚集关系? [英] Do pointer/reference data members indicate an association or aggregaation relationship in UML?

查看:108
本文介绍了指针/引用数据成员是否指示UML中的关联或聚集关系?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有点困惑.

您可以说它通过指针使用"了对象-因此是关联. 但这听起来像是聚合-有一个"对象,但是当该对象死亡时,这并不意味着所引用的对象死亡.

You could say it 'uses' the object via the pointer - therefore association. But it also sounds like aggregation - 'has an' object but when this object dies that doesn't mean the referenced object dies.

在UML中,哪一个最有意义?

Which one makes most sense in UML?

推荐答案

它可以指示关联,聚合和事件组成.两者之间的区别在于语义,而不是静态的或特定于实现的.

It can indicate association, aggregation and event composition. The difference between the three is semantic and not static or implementation specific.

  1. 如果指向的类与所属类具有 lifecycle 依赖关系(如果没有它,就不能存在整个整体的一部分,例如哈希图中的入口类),那么它就是一个组合.
  2. 如果指向的类是所属类的部分(语义关系,即应用程序中的控制器之间共享的数据库连接),则它是一个聚合.
  3. 如果指针类用于另一件事(缓存,某些计算中的中间值等),则它可能是一个简单的关联.
  1. If the pointed class has a lifecycle dependency with the owning class (a part of a whole that cannot exist without it, like entry classes in a hashmap) then it is a composition.
  2. If the pointed class is a part of the owning class (semantic relation, i.e. a database connection that is shared between controllers in an application) then it is an aggregation.
  3. If the pointer class is used for another thing (caching, intermediate values in some calculation, etc) then it is probably a simple association.

但是UML为不同的解释留出了很多空间,因此您永远不会在这里得到正确"的答案.

But UML leaves a LOT of space for different interpretations, so you will never get a "correct" answer here.

这篇关于指针/引用数据成员是否指示UML中的关联或聚集关系?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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