Compsite定义
- 组合模式 : 将对象组合成树结构以表示"部分整体"的层次结构. 组合模式使得用户对单个对象和组合对象的使用具有一致性.
- component 节点的统一接口, 统一节点的操作
- leaf 属于叶子节点
- composite属于枝节点 , 可以有子节点
应用场景真的超级多, 菜单栏, 公司组织架构, 文件系统
Compsite的一些取舍
- 安全性与透明性, 两者是矛盾的
- 叶节点与非叶节点的某些行为不一致, 但是有需要提供一个一致的行为接口
- 透明性表示的是 越透明暴露的信息越多
- 但客户端的使用复杂程度降低
- 反之即为安全组合模式