chp8-设计模式导论.pptVIP

  • 1
  • 0
  • 约1.03万字
  • 约 52页
  • 2019-10-27 发布于湖北
  • 举报
Abstract Factory Design Pattern Style getComponentA() getComponentB() Client doOperation( Style myStyle ) Style1 getComponentA() getComponentB() Style2 getComponentA() getComponentB() ComponentA ComponentB Style1ComponentA Style1ComponentB Style2ComponentA Style2ComponentB Collection * TP-52 Explains to Abstract Factory Client的doOperation( Style myStyle )方法构建了一个collection实例,例如myStyle是Style1类的对象 myStyle的两个操作将分别产生Style1ComponentA和Style1ComponentB对象 这种模式能够始终确保一个协调的风格! * TP-52 Abstract Factory Design Pattern ----Alternative Way Style getComponentA() getComponentB() Client doOperation() Style1 getComponentA() getComponentB() Style2 getComponentA() getComponentB() ComponentA ComponentB Style1ComponentA Style1ComponentB Style2ComponentA Style2ComponentB Collection getComponentA() getComponentB() 没有参数 聚合了Style类 不直接引用Style类 运行时实例化 * TP-52 Summary? What Design Pattern ?? -- class combination and algorithm fulfilling a common design purpose. *通过类的组合和相关算法完成公共的设计目标 ——设计模式 * TP-52 设计模式的特征:观点、角色、层次 1. 客户任务 2. 建立任务 A C A. Static viewpoint B. Dynamic viewpoint 3. 任务:设计模式的应用 D B (i) Abstract level (ii) Concrete level (class model) (sequence or state diagram) : Reference direction * TP-52 设计模式两个观点 静态观点:解决如何创建,由什么创建对象的问题 动态观点:解决怎样发挥模式的功能问题 * TP-52 AntiqueKStyle getWallCabinet() getFloorCabinet() 静态观点(如何创建) KitchenStyle getWallCabinet() getFloorCabinet() ModernKStyle getWallCabinet() getFloorCabinet() WallCabinet FloorCabinet AntiqueWallCabinet AntiqueFloorCabinet FloorCabinet getFloorCabinet() { return new AntiqueFloorCabinet(); } … … FloorCabinet getFloorCabinet() { return new ModernFloorCabinet(); } * TP-52 getWallCabinet() Abstract Factory Application Sequence Diagram myStyle:KitchenStyle Client myStyle: ModernKStyle myStyle: AntiqueKStyle renderKitchen ( myStyle ) wallCabinet1: ModernWallCabinet wallCabinet1: AntiqueWallCabinet ModernWallCabinet() getWallCabinet() AntiqueWallCabinet() myStyle. getWallCabinet() -- IF myStyle BELONGS TO ModernKStyle -- -- IF myS

文档评论(0)

1亿VIP精品文档

相关文档