The composite pattern describes thata group of objects are to be treated in the same way as a single instance of an object.The intent of a composite is to "compose" objects into tree structures to represent part-whole hierarchies. Implementing the composite pattern lets clients treat individual objects and compositions uniformly.[1]
WIKI的解释很直观,组合模式强调的是一个对象和一组对象的无差别处理。
http://blog.youkuaiyun.com/feixiaoxing/article/details/7078836
上文这个家伙的举例也不错,C中常见的组合模式就是2级链表的遍历。
但原文代码不直观,尝试举例如下:系统有一个设备链,每个节点挂接同一类型的设备,这样就形成了2级链表。
如果需要对所有设备进行遍历,就需要用到该设计模式。