UML 类图:组合 vs 聚合 [英] UML class diagram: composition vs agregation

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

问题描述

我想了解组合聚合关系之间的区别.

I want to understand the difference between composition and aggregation relationship.

有人知道解释所有关系的 UML 类图的网站吗?

Does anyone know a site that explains the UML class diagrams for all relationships?

推荐答案

组合和聚合与级联删除行为有关.

Composition and aggregation have to do with cascading delete behavior.

子对象在父对象之外是否有自己的生命?如果是,则需要聚合.

Do the child objects have a life of their own beyond the parent? If yes, you need aggregation.

如果删除了父级,是否也需要删除子级?如果是,则需要合成.

If the parent is deleted, do the children need to be deleted as well? If yes, you need composition.

假设您有一个模型,其中有一个 School 类、一个 Building 类和一个 Student 类.School 与 Building 是一对多关系,与 Student 是一对多关系.

So let's say you have a model where there's a School class, a Building class, and a Student class. A School has a one-to-many relationship with Building and a one-to-many relationship with Student.

学校与建筑的关系是构成的一个例子.如果您关闭学校,您可能会决定推平建筑物.

The School-to-Building relationship is an example of composition. If you close the School, you might decide to bulldoze the buildings.

学校与学生的关系是聚合.如果你关闭学校,你肯定不会决定谋杀所有学生.

The School-to-Student relationship is aggregation. If you close the school, you certainly won't decide to murder all the Students.

您可以在此处阅读鲍勃·马丁叔叔对此的看法.

You can read what Uncle Bob Martin has to say about it here.

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

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