设计模式原则之接口隔离原则

                                                                                                        接口隔离原则

1.什么是接口隔离原则

  • 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.(类间的依赖关系应该建立在最小的接口上)

       通过简单的代码还原开篇的问题

需求如下

类A通过接口会依赖(使用)类C 但是类A只会使用到接口中的1,2,3方法

类B通过接口会依赖(使用)类D 但是类B只会使用到接口中的1,4,5方法

最初的接口中有五个方法

猜你喜欢

转载自www.cnblogs.com/newbee0101/p/11706047.html