六大设计原则-接口隔离原则【Interface Segregation Principle】
2018-01-24 17:26
204 查看
六大设计原则
单一职责原则里式替换原则
依赖倒置原则
接口隔离原则
迪米特原则
开闭原则
接口隔离原则
定义: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(类间的依赖关系应该建立在最小的接口上)
定义概括:
建立单一接口,不要建立臃肿庞大的接口。再通俗的一点讲:接口尽量细化,同时接口中的方法尽量的少。
示例:
分析:
我们发现我们的接口 IPettyGirl 接口设计是有缺陷地,过于庞大了,容纳了一些可变的因素,根据接口隔离原则,星探 AbstractSearcher 应该依赖与具有部分特质的女孩子,而我们却把这些特质都封装了起来,放到了一个接口中了,封装过渡了!
修改后:
通过分散定义多个接口,可以预防未来变更的扩散,提高系统的灵活性和可维护性。
需要记住的内容:
据接口隔离原则拆分接口时,必须首先满足单一职责原则。
其它:
嘻嘻,给我自己看的,反正其他人也看不懂。可以类似于同步接口中的同步终端与平台做对比分析。
相关文章推荐
- 六大设计原则--接口隔离原则【 Interface Segregation Principle】
- 设计模式六大原则——接口隔离原则(ISP,Interface Segregation Principle)
- 设计模式六大原则(4):接口隔离原则(Interface Segregation Principle)
- 设计模式六大原则(4)接口隔离原则(Interface Segregation Principle)
- 设计模式六大原则(4):接口隔离原则ISP(Interface Segregation Principle)
- 设计模式六大原则(4):接口隔离原则(Interface Segregation Principle)
- IOS设计模式的六大设计原则之接口隔离原则(ISP,Interface Segregation Principle)
- 【六大设计原则】4. 接口隔离原则 -Interface Segregation Principle
- 设计模式六大设计原则之接口隔离原则(Interface Segregation Principle)
- IOS设计模式的六大设计原则之接口隔离原则(ISP,Interface Segregation Principle)
- 设计原则-接口隔离原则(Interface Segregation Principle)
- IOS设计模式的六大设计原则之接口隔离原则(ISP,Interface Segregation Principle)
- 设计原则-接口隔离原则(Interface Segregation Principle)
- IOS设计模式的六大设计原则之接口隔离原则(ISP,Interface Segregation Principle)
- Interface Segregation Principle (ISP) - OO设计的接口分隔原则
- Java设计模式之接口隔离原则(Interface Segregation Principle, ISP)
- 6大设计原则之接口隔离原则(Interface Segregation Principle)。
- 设计模式6大原则之接口隔离原则(Interface Segregation Principle)
- Interface Segregation Principle (ISP) - OO设计的接口分隔原则