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.
本文探讨了面向对象设计中的聚合与组合概念,解析了二者之间的区别及其应用场景。通过具体实例说明了聚合表示一种较弱的关系,子对象可以独立于父对象存在;而组合则暗示了一种更强的关系,即子对象无法脱离父对象单独存在。此外还介绍了依赖关系作为关联的一种较弱形式。
2257

被折叠的 条评论
为什么被折叠?



