Files
Hui-s-notebook/接口隔离原则.md
2023-09-10 10:50:53 +08:00

882 B

  • 实例接口,在 Java 中声明一个类,然后用 new 关键字产生一个实例,它是对一个类型的事物的描述,这是一种接口
  • 类接口,Java 中经常使用的 interface 关键字定义的接口

隔离原则

  • Clients should not be forced to depend upon interfaces that they don't use.(客户端不应该依赖它不需要的接口。)
  • The dependency of one class to another one should depend on the smallest possible interface.(类间的依赖关系应该建立在最小的接口上。)

接口尽量细化, 同时接口中的方法尽量少

保证接口的纯洁性

  • 接口要尽量小

  • 接口要高内聚

  • 定制服务

  • 接口设计是有限度的

  • 一个接口只服务于一个子模块或业务逻辑

  • 通过业务逻辑压缩接口中的 public 方法

  • 已经被污染的接口, 尽量去修改

  • 了解环境, 拒绝盲从