接口隔离原则

1.定义:客户端不要依赖它不需要的接口,一个类对另一个类的依赖应该建立在最小的接口上。

2.注意适度原则,一定要适度

3.优点:符合我们常说的高内聚低耦合的设计思想,从而使得类具有很好的可读性、可扩展性和可维护性。

4.实例目录package

5.实例UML类图

6.代码

1 package com.geely.design.principle.interfacesegregation;
2 
3 public interface IAnimalAction {
4     void eat();
5     void fly();
6     void swim();
7 }
 1 package com.geely.design.principle.interfacesegregation;
 2 
 3 public class Bird implements IAnimalAction{
 4     public void eat() {
 5 
 6     }
 7 
 8     public void fly() {
 9 
10     }
11 
12     public void swim() {
13 
14     }
15 }
1 package com.geely.design.principle.interfacesegregation;
2 
3 public interface IEatAnimalAction {
4     void eat();
5 }
1 package com.geely.design.principle.interfacesegregation;
2 
3 public interface ISwimAnimalAction {
4     void swim();
5 }
1 package com.geely.design.principle.interfacesegregation;
2 
3 public interface IFlyAnimalAction {
4     void fly();
5 }
 1 package com.geely.design.principle.interfacesegregation;
 2 
 3 public class Dog implements ISwimAnimalAction,IEatAnimalAction {
 4     public void eat() {
 5 
 6     }
 7 
 8     public void swim() {
 9 
10     }
11 }
posted @ 2019-01-01 14:07  逢春  阅读(130)  评论(0)    收藏  举报