标签:维护 pre uml 接口隔离原则 reg 接口 代码 alac action
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 }
标签:维护 pre uml 接口隔离原则 reg 接口 代码 alac action
原文地址:https://www.cnblogs.com/linbq1911/p/10204711.html