C++设计模式 模板分类

一、从封装变化角度对模式分类

1. 组件协作
  • Template Method
  • Strategy
  • Observer / Event
2. 单一职责
  • Decorator
  • Bridge
3. 对象创建
  • Factory Method
  • Abstract Factory
  • Prototype
  • Builder
4. 对象性能
  • Singleton
  • Flyweight
5. 接口隔离
  • Facade
  • Proxy
  • Mediator
  • Adapter
6. 状态变化
  • Memento
  • State
7. 数据结构
  • Composite
  • Iterator
  • Chain of Responsibility
8. 行为变化
  • Command
  • Visitor
9. 领域变化
  • Interpreter

二、重构获得模式 Refactoring to Patterns

  • 好的面向对象设计:指可以满足"应对变化,提高复用"设计;
  • “需求的频繁变化”, “寻找变化点”然后在变化点处应用设计模式,从而更好地应付需求的变化, “什么时候、什么地点应用设计模式” 比 “理解设计模式结构本身” 更为重要
  • 设计模式的应用不宜先入为主 Refactoring to Patterns

三、重构关键技法(指导思想)

  • 静态 to 动态
  • 早绑定 to 晚绑定
  • 继承 to 组合
  • 编译时依赖 to 运行时依赖
  • 紧耦合 to 松耦合

猜你喜欢

转载自blog.csdn.net/weixin_40437821/article/details/111462516