设计原理 SOLID

  • A class should have only a single responsibility
    单一职责(S): 一个类只承担一个职责,引起类变化的因素永远不要多余一个.
  • A class should be open for extension but closed for modification
    开闭原则(O): 不需要修改就能扩展类的行为,对拓展开放,对修改关闭.
  • A type must be substitutable by its subtypes without altering the correctness of the application
    替换原则(L): 子类代替父类时,对系统毫无影响,所有引用基类的地方必须能透明地使用其子类的对象.
  • Clients of a class should not be forced to depend on those of its methods that they don’t use
    接口隔离(I):客户端不应该强制依赖那些他们没有使用到的接口,类不需强制实现接口中不需要的方法和属性.
  • High-level classes should not dependent on low-level classes. Both of then shoud depend on abstractions. b. Abstractions should not depend upon details. Details should depend upon abstractions.
    依赖倒置(D):上级组件不依赖下级组件,二者都依赖抽象。抽象不取决于下级组件,其来自于上级组件的需求,下级组件完成抽象.