为什么在一些示例中将组合标记为聚合的子集?

huangapple go评论114阅读模式
英文:

Why is composition labelled as a subset of aggregation in some illustrations?

问题

关于我在网上找到的图像。它将Composition标记为Aggregation的一个子集。根据我的理解,Composition是一种紧密耦合的形式,就像我们在一个对象内部实例化另一个对象一样。而Aggregation是一种松散耦合的形式,有点像依赖注入。它们似乎不同,那么为什么Composition会是Aggregation的一个子集?

图像:
https://algodaily.com/lessons/association-aggregation-composition-casting

英文:

Referring to an Image I found online. It labels Composition as a subset of Aggregation.
As per my understanding Composition is a form of tight coupling like when we instantiate an object inside another object. While Aggregation is a form of loose coupling kind of like a Dependancy Injection. They both seem different so why would Composition be a subset of Aggregation?

Image:
https://algodaily.com/lessons/association-aggregation-composition-casting

答案1

得分: 4

因为这是历史上的最先进技术,对于UML 2.5并不适用。将聚合作为属性解释在UML 2.5的第110页:

  • none | 表示该属性没有聚合语义。
  • shared | 表示该属性具有共享聚合语义。共享聚合的精确语义因应用领域和建模者而异。
  • composite | 表示该属性以组合方式聚合,即组合对象对于所包含对象的存在和存储负有责任(请参阅第11.2.3节中部分的定义)。

因此,实际上,这两者并列存在,shared 没有任何语义。早期的UML规范曾有一些定义,使 shared 成为某种子集。但这只是历史。尽管如此,人们难以摆脱这种思维。

英文:

Because it's historical state of the art an not true for UML 2.5. Aggregation as attribute of a Property is explained on p. 110 of UML 2.5:

>- none | Indicates that the Property has no aggregation semantics.
>- shared | Indicates that the Property has shared aggregation semantics. Precise semantics of shared aggregation varies by application area and modeler.
>- composite | Indicates that the Property is aggregated compositely, i.e., the composite object has responsibility for the existence and storage of the composed objects (see the definition of parts in 11.2.3).

So actually both stand side-by-side with shared having no semantics whatsoever. Former UML specs had some definition which made shared some kind of subset. But that is just history. Though, you don't get it out of people's heads.

答案2

得分: 0

Composition 是一种专门的聚合形式。在 composition 中,如果父对象被销毁,那么子对象也会停止存在。Composition 实际上是一种强类型的聚合,有时被称为“死亡”关系。

英文:

Composition is a specialized form of aggregation. In composition, if the parent object is destroyed, then the child objects also cease to exist. Composition is actually a strong type of aggregation and is sometimes referred to as a “death” relationship.

huangapple
  • 本文由 发表于 2023年2月7日 04:19:05
  • 转载请务必保留本文链接:https://go.coder-hub.com/75366160.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定