组合和聚合有什么区别? [重复]

时间:2020-12-19 22:28:19

What is the difference between composition and aggregation? can anybody give me a sample of this OOAD?

组合和聚合有什么区别?谁能给我一个这个OOAD的样本?

4 个解决方案

#1


6  

Found here

在这里找到

"Both aggregation and composition are special kinds of associations. Aggregation is used to represent ownership or a whole/part relationship, and composition is used to represent an even stronger form of ownership. With composition, we get coincident lifetime of part with the whole. The composite object has sole responsibility for the disposition of its parts in terms of creation and destruction.

“聚合和组合都是特殊的关联。聚合用于表示所有权或整体/部分关系,而组合用于表示更强大的所有权形式。通过组合,我们得到与整体相关的一致生命。复合对象全权负责在创建和销毁方面处理其部件。

Moreover, the multiplicity of the aggregate end may not exceed one; i.e., it is unshared. An object may be part of only one composite at a time. If the composite is destroyed, it must either destroy all its parts or else give responsibility for them to some other object. A composite object can be designed with the knowledge that no other object will destroy its parts.

而且,总端的多重性不得超过一个;即,它是非共享的。对象可以一次只是一个复合的一部分。如果复合材料被销毁,它必须要么销毁它的所有部件,要么将它们交给其他一些对象。可以设计复合对象,使其知道没有其他对象会破坏其部件。

Composition can be used to model by-value aggregation, which is semantically equivalent to an attribute. In fact, composition was originally called aggregation-by-value in an earlier UML draft, with “normal” aggregation being thought of as aggregation-by-reference. The definitions have changed slightly, but the general ideas still apply. The distinction between aggregation and composition is more of a design concept and is not usually relevant during analysis." John Moore

组合可用于建模按值聚合,其在语义上等同于属性。实际上,组合最初在早期的UML草案中称为按值聚合,“正常”聚合被认为是按引用聚合。定义略有改变,但一般的想法仍然适用。聚合和组合之间的区别更多的是设计概念,在分析过程中通常不相关。“John Moore

#2


24  

Consider a student, the student's brain, and the school the student attends.

考虑学生,学生的大脑以及学生所在的学校。

The brain is a part of the student. If the student is destroyed, so is the brain. This is composition.

大脑是学生的一部分。如果学生被摧毁,大脑也是如此。这是作文。

The student has a school. The student survives the school's destruction, and vice versa. This is aggregation.

这个学生有一所学校。学生在学校的破坏中幸存下来,反之亦然。这是聚合。

#3


0  

Relevant answer to your question here: http://ootips.org/uml-hasa.html

这里你的问题的相关答案:http://ootips.org/uml-hasa.html

In short: both composition and aggregation are acyclic has-a relationships consisting of a part and a whole. The difference is that with composition, the whole is responsible for creating (and deleting) its parts.

简而言之:组成和聚合都是非循环的 - 由一部分和一部分组成的关系。不同之处在于,使用合成,整体负责创建(和删除)其部分。

#4


0  

http://en.wikipedia.org/wiki/Object-oriented_programming
http://en.wikipedia.org/wiki/Object_composition
http://en.wikipedia.org/wiki/Object_composition#Aggregation

http://en.wikipedia.org/wiki/Object-oriented_programming http://en.wikipedia.org/wiki/Object_composition http://en.wikipedia.org/wiki/Object_composition#Aggregation

#1


6  

Found here

在这里找到

"Both aggregation and composition are special kinds of associations. Aggregation is used to represent ownership or a whole/part relationship, and composition is used to represent an even stronger form of ownership. With composition, we get coincident lifetime of part with the whole. The composite object has sole responsibility for the disposition of its parts in terms of creation and destruction.

“聚合和组合都是特殊的关联。聚合用于表示所有权或整体/部分关系,而组合用于表示更强大的所有权形式。通过组合,我们得到与整体相关的一致生命。复合对象全权负责在创建和销毁方面处理其部件。

Moreover, the multiplicity of the aggregate end may not exceed one; i.e., it is unshared. An object may be part of only one composite at a time. If the composite is destroyed, it must either destroy all its parts or else give responsibility for them to some other object. A composite object can be designed with the knowledge that no other object will destroy its parts.

而且,总端的多重性不得超过一个;即,它是非共享的。对象可以一次只是一个复合的一部分。如果复合材料被销毁,它必须要么销毁它的所有部件,要么将它们交给其他一些对象。可以设计复合对象,使其知道没有其他对象会破坏其部件。

Composition can be used to model by-value aggregation, which is semantically equivalent to an attribute. In fact, composition was originally called aggregation-by-value in an earlier UML draft, with “normal” aggregation being thought of as aggregation-by-reference. The definitions have changed slightly, but the general ideas still apply. The distinction between aggregation and composition is more of a design concept and is not usually relevant during analysis." John Moore

组合可用于建模按值聚合,其在语义上等同于属性。实际上,组合最初在早期的UML草案中称为按值聚合,“正常”聚合被认为是按引用聚合。定义略有改变,但一般的想法仍然适用。聚合和组合之间的区别更多的是设计概念,在分析过程中通常不相关。“John Moore

#2


24  

Consider a student, the student's brain, and the school the student attends.

考虑学生,学生的大脑以及学生所在的学校。

The brain is a part of the student. If the student is destroyed, so is the brain. This is composition.

大脑是学生的一部分。如果学生被摧毁,大脑也是如此。这是作文。

The student has a school. The student survives the school's destruction, and vice versa. This is aggregation.

这个学生有一所学校。学生在学校的破坏中幸存下来,反之亦然。这是聚合。

#3


0  

Relevant answer to your question here: http://ootips.org/uml-hasa.html

这里你的问题的相关答案:http://ootips.org/uml-hasa.html

In short: both composition and aggregation are acyclic has-a relationships consisting of a part and a whole. The difference is that with composition, the whole is responsible for creating (and deleting) its parts.

简而言之:组成和聚合都是非循环的 - 由一部分和一部分组成的关系。不同之处在于,使用合成,整体负责创建(和删除)其部分。

#4


0  

http://en.wikipedia.org/wiki/Object-oriented_programming
http://en.wikipedia.org/wiki/Object_composition
http://en.wikipedia.org/wiki/Object_composition#Aggregation

http://en.wikipedia.org/wiki/Object-oriented_programming http://en.wikipedia.org/wiki/Object_composition http://en.wikipedia.org/wiki/Object_composition#Aggregation