关联,聚合和组合的区别 [英] Difference between association, aggregation and composition

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

问题描述

有什么关联,聚合和组合的区别?请在执行方面解释。

What is the difference between association, aggregation and composition? Please explain in terms of implementation.

推荐答案


  • 协会是一个关系,其中所有的对象都有自己的生命周期和没有主人。

  • Association is a relationship where all objects have their own lifecycle and there is no owner.

    让我们师生的例子。多个学生可以单老师和一个学生关联可以与多个教师联系在一起,但有对象和两者各有自己的生命周期之间没有所有权。两者都可以创建并单独删除。

    Let’s take an example of Teacher and Student. Multiple students can associate with single teacher and single student can associate with multiple teachers, but there is no ownership between the objects and both have their own lifecycle. Both can be created and deleted independently.

    汇聚是协会,所有的物体都有自己的生命周期中的一种特殊形式,但所有权和子对象不能属于另一个父对象。

    Aggregation is a specialised form of Association where all objects have their own lifecycle, but there is ownership and child objects can not belong to another parent object.

    让我们部和老师的例子。一名教师不能属于多个部门,但如果我们删除部门,老师对象的的被破坏。我们可以想一想,它作为一个有的关系。

    Let’s take an example of Department and teacher. A single teacher can not belong to multiple departments, but if we delete the department, the teacher object will not be destroyed. We can think about it as a "has-a" relationship.

    组成再次聚集专门的表格,我们可以把这个作为死亡的关系。这是一个强类型聚集。子对象不具有生命周期,如果父对象被删除,所有子对象也将被删除。

    Composition is again specialised form of Aggregation and we can call this as a "death" relationship. It is a strong type of Aggregation. Child object does not have its lifecycle and if parent object is deleted, all child objects will also be deleted.

    让我们再次拿房子和房间之间的关系的一个例子。房子可以包含多个房间 - 有房间没有独立生活和任何房间不能属于两个不同的房子。如果我们删除的房子 - 房间会被自动删除。

    Let’s take again an example of relationship between House and Rooms. House can contain multiple rooms - there is no independent life of room and any room can not belong to two different houses. If we delete the house - room will automatically be deleted.

    让我们问题和选项之间的另一个例子关系。单个问题可以有多种选择和选项不能属于多个问题。如果我们删除的问题,选项会被自动删除。

    Let’s take another example relationship between Questions and Options. Single questions can have multiple options and option can not belong to multiple questions. If we delete the questions, options will automatically be deleted.

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

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