composition组合和aggregation聚合之间的区别 difference 拂晓风起

In UML, composition is depicted as a filled diamond and a solid line. It always implies a multiplicity of 1 or 0..1, as no more than one object at a time can have lifetime responsibility for another object.

The more general form, aggregation, is depicted as an unfilled diamond and a solid line. The image below shows both composition and aggregation. The C++ code below shows what the source code is likely to look like.

AggregationAndComposition.svg

参考:http://en.wikipedia.org/wiki/Object_composition

简单来说:

composition组合,是实心菱形,个体不可以脱离整体存在,生命周期一致

aggregation聚合,是空心菱形,个体生命周期跟整体的可以不一致

kenkofox@qq.com https://github.com/kenkozheng 欢迎投简历给我,一线大厂工作机会
原文地址:https://www.cnblogs.com/kenkofox/p/1885836.html