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聚合,是空心菱形,个体生命周期跟整体的可以不一致

posted @ 2010-11-23 20:10  拂晓风起-Kenko  阅读(468)  评论(0编辑  收藏  举报