第五章结构型模式2.pptVIP

  • 5
  • 0
  • 约5.52千字
  • 约 25页
  • 2018-02-03 发布于河北
  • 举报
第五章结构型模式2

5.1 Composite模式 意图 将对象组合成树型表示“部分—整体” 的层次结构。Composite 使得用户对单个对象和组合对象的使用具有一致性。(具有共同接口) 叶节点 LeafNode LeafComponent 非叶节点 NonLeafNode CompositeComponent 树型结构 Component aPicture:Graphic aPicture:Graphic aLine:Graphic aText:Graphic aLine:Graphic aRectangle :Graphic aRectangle :Graphic 典型的由递归组合的Graphic对象组成的组合对象结构 …… …… 适用性 以下情况使用Composite模式: 1. 你想表示的对象的部分—整体层次结构。 2. 你希望用户忽略组合对象与单个对象的不同,用户将统一地使用组合结构中 的所有对象。 Component NonLeafNode 1..n 有1个或多个节点 包含的每个对象 都是Component 对象 结构图 Component operation() add(Component) remove(Component) getChild( )

文档评论(0)

1亿VIP精品文档

相关文档