我们给出 UML 中的相关定义:元素名称符号图例含义
AssociationA 和 B 相互调用和访问对方的元素。
A and B call and access each other’s elements.
AggregationA 中拥有一个 B,但 B 脱离于 A 仍然可以独立存活。
A has a B, and B can outlive A.
A "uses" B = Aggregation : B exists independently (conceptually) from A.
CompositionA 中拥有一个 B,B 脱离 A 后在系统中没有任何存活的意义。
A has a B, and B depends on A.
A "owns" B = Composition : B has no meaning or purpose in the system without A.
我们可以从不同的角度来理解和区分这三种关系:AssociationAggregationComposition
OwnerNo ownerSingle ownerSingle owner
LifetimeHave their own lifetimeH