设计模式之接口隔离原则

接口隔离原则

接口隔离原则

  • Clients should not be force do depend upon interfaces that they don’t need.
  • The dependency of one class to another one should depend on the smallest possible interface.
  • 客户端不应该依赖不需要的接口
  • 类之间的依赖关系应该是最小的接口上。
  • 对接口的规范
    • 接口尽量小(如果与lsp冲突,以lsp为准)
    • 接口要高内聚(提高接口,类内部处理能力,减少对外的交互)
    • 要明白接口设计是有限度的。
  • 实践
    • 一个接口只服务于一个子模块或者业务逻辑
    • 通过业务逻辑压缩接口中的public 方法接口要时常回顾,尽量的精简
    • 已经被污染的接口,尽量去修改,若有风险,使用适配器适配
    • 一切从业务触发.