问题描述
聚合意味着关系孩子可以独立于父母存在。示例:Class(parent)和Student(child)。删除课程,学生仍然存在。
组合意味着小孩不能独立于父母的关系。示例:House(parent)和Room(child)。
上述两种是包含(因此是父子关系)的形式。 p>
依赖关系是一种较弱的关系形式,代码术语表示一个类使用另一个参数或返回类型。
依赖关系是一种关联的形式。
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.
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.
Dependency is a form of association.
这篇关于聚合,组合和依赖关系有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!