源码地址:https://github.com/ldy1993/ToolforAS.git
-
接口隔离原则 Interface Segregation Principle
-
一、定义
-
1、客户端不应该依赖它不需要的接口(一个接口中的方法不应该冗余)Clients should not be forced to depend upon interfaces that they don’t use.
2、类间的依赖关系应该建立在最小的接口上,The dependency of one class to another one should depend on the smallest possible interface.
-
-
例如下面
-
interface Behavior { void fly(); void running(); void wave(); }
正确的示范是分别拆分行为中专属于鸟类的,专属于人类的,还有共有的,分成三个接口。
interface BehaviorFly {
void fly();
}
interface BehaviorRun {
void running();
}
interface BehaviorWave {
void wave();
}
代码图