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

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

问题描述

聚合、组合和依赖之间有什么区别?

What is the difference between aggregation, composition and dependency?

推荐答案

聚合 暗示一种关系,其中子级可以独立于父级而存在.示例:班级(家长)和学生(孩子).删除班级,学生仍然存在.

Aggregation implies a relationship where the child can exist independently of the parent. Example: Class (parent) and Student (child). Delete the Class and the Students still exist.

组合意味着一种关系,其中子级不能独立于父级而存在.示例:House(父母)和 Room(孩子).房间不独立于房子.

Composition implies a relationship where the child cannot exist independent of the parent. Example: House (parent) and Room (child). Rooms don't exist separate to a House.

以上两种是遏制的形式(因此是父子关系).

The above two are forms of containment (hence the parent-child relationships).

依赖是一种较弱的关系形式,在代码方面表示一个类通过参数或返回类型使用另一个.

Dependency is a weaker form of relationship and in code terms indicates that a class uses another by parameter or return type.

依赖是一种关联.

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

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