设计原则与设计模式

94 阅读1分钟

SOLID 设计原则

  • S: Single Responsibility 单一职责原则

Every class should have a single responsibility and that responsibility should be entirely met by that class

  • O: Open/Closed 开闭原则

Open for extension but closed for modification; inheritance is used for this, e.g. through the use of inherited abstract base classes

  • L: Liskov Substitution Principle 里氏替换原则

If S<:T (“S is a subtype of T”) then a T object can be replaced with an S object and no harm done

  • I: Interface Segregation 接口隔离原则

Client code should not have to implement interfaces it doesn’t need

  • D: Dependency Inversion 依赖倒置原则

High level, complex modules should not depend on low-level, simple models — use abstraction, and implementation details should depend on abstractions, not the other way around

GRASP(General Responsibility Assignment Software Patterns) 设计原则

  • Creator
  • Information Expert
  • High Cohesion
  • Low Coupling
  • Controller

设计模式

  • 创建型模式
    • Factory Method 工厂方法模式
    • Builder 建造者模式
    • Prototype 原型模式
    • Singleton 单例模式
  • 结构型模式
    • Adapter 适配器模式
    • Decorator 装饰器模式
    • Facade 外观模式
  • 行为型模式
    • Strategy 策略模式
    • State 状态模式
    • Observer 观察者模式
    • Memento 备忘录模式