Definition

Interface Segregation Principle,即接口隔离原则。用多个专门的接口,而不是使用单一的总接口,客户端不应该依赖它不需要的接口。

一个类对另一个类的依赖应该建立在最小的接口上。
建立单一的接口,而不是接口庞大臃肿的接口。
尽可能细化接口,接口中的方法尽可能少。
注意适度原则。

Advantage

  • 提高了可读性。
  • 提高了拓展性。
  • 提高了可维护性。

Code Example

Design Principle - Interface Segregation Principle

Design Principle - Interface Segregation Principle

Design Principle - Interface Segregation Principle

Bird类不需要run()方法,Dog类也不需要fly()方法,基于接口隔离原则,进行接口细化。

Design Principle - Interface Segregation Principle

Design Principle - Interface Segregation Principle

Design Principle - Interface Segregation Principle

Design Principle - Interface Segregation Principle

Design Principle - Interface Segregation Principle

相关文章:

  • 2021-11-28
  • 2021-11-23
  • 2021-09-08
  • 2021-04-10
  • 2022-12-23
  • 2021-06-10
  • 2022-01-23
  • 2021-09-06
猜你喜欢
  • 2021-10-15
  • 2021-05-22
  • 2022-01-10
  • 2022-12-23
  • 2021-05-23
相关资源
相似解决方案