组合和聚合之间有什么区别? [英] What is the difference between composition and aggregation?

查看:113
本文介绍了组合和聚合之间有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

组合和聚合之间有什么区别? 有人可以给我这个OOAD的样品吗?

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

推荐答案

在此处找到

聚合和组合都是特殊的关联.聚合用于表示所有权或整体/部分关系,而组合用于表示更强的所有权形式.通过组合,我们得到零件的寿命一致

"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.

此外,合计末端的多重性不得超过1;即未共享.一个对象一次只能是一个合成的一部分.如果复合材料被破坏,则它必须要么破坏其所有部件,要么将它们的责任归于其他物体.可以在没有其他对象会破坏其零件的知识的情况下设计复合对象.

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.

组合可用于对按值聚合建模,该聚合在语义上等效于属性.实际上,在早期的UML草案中,组合最初被称为按值聚合,正常"聚合被认为是按引用聚合.定义稍有变化,但总体思路仍然适用.聚合和成分之间的区别更多是一种设计概念,在分析过程中通常不相关." 约翰·摩尔

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

这篇关于组合和聚合之间有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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