关联与聚合之间的差异 [英] difference between association and aggregation

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

问题描述

我了解聚合和合成之间的区别,但是我在关联方面有些挣扎.我目前的理解是,彼此使用"时,类之间存在关联,例如,在方法调用期间将一个对象传递给另一个对象.另请参阅:

I understand the difference between aggregation and composition but I am struggling a bit with association. My current understanding is that an association exists between classes when ‘they use each other’, for example, one object is passed to the other during a method call. See also:

http://www.codeproject.com/Articles/330447/Understanding-Association -聚合与合成

两个对象都独立存在,与聚合相反,没有一个对象是另一个的容器类.这是否意味着两个对象都必须具有其他对象的副本(例如1:m关系),或者关联如何存储".任何反馈将不胜感激.

Both objects exist independently and, in contrast to aggregation, no object is a container class of the other. Does this mean that both objects MUST have a copy of the other(s) (e.g. 1:m relationship) or how else is the association ‘stored’. Any feedback would be very much appreciated.

推荐答案

来自UML上层结构2.4.1:

From the UML Superstructure 2.4.1:

一个关联声明关联类型的实例之间可以存在链接.链接是一个元组,在关联的每个末端都有一个值,其中每个值都是该末端类型的一个实例. (UML上层建筑,第37页)

An association declares that there can be links between instances of the associated types. A link is a tuple with one value for each end of the association, where each value is an instance of the type of the end. (UML Superstructure, Page 37)

仅此而已.而且非常模糊因此,也很难理解.我定义的(在我所教的课程中)是一个从依赖到构成的链接层次结构,其中:

Nothing more, nothing less. and very vague. Because of this, it is also very hard to understand. What I defined (In a course I teach) is a hierarchy of links from dependency to composition where:

  1. AB的依赖关系意味着A使用B但间接使用(例如,通过接收它的实例并将其转发到其他对象).
  2. AB的关联意味着A直接使用B(例如,通过调用方法)
  3. AB的聚合意味着(cemally)BA的一部分,但是B可以共享,并且如果删除A,则不会删除B.请注意,这没有说明组成部分"的实现方式.
  4. AB的组合类似于聚合,其中B无法共享,并且如果删除A,其所有聚合(B s)也将被删除.
  1. Dependency from A to B means that A uses B but indirectly (say by receiving instances of it and forwarding them to other objects).
  2. Association from A to B means that A uses B directly, (for example by calling methods)
  3. Aggregation from A to B means that B is part of A (semantically) but B can be shared and if A is deleted, B is not deleted. Note that this says nothing about how the "is part" is implemented.
  4. Composition from A to B is like Aggregation, where B cannot be shared and if A is deleted, all of its aggregates (Bs) are deleted also.

这篇关于关联与聚合之间的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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