1、定义
    客户端不应该依赖它不需要的接口;类之间的依赖应该建立在最小的接口上。

    2、举例说明

    1. //美女接口
    2. public interface IPettyGirl {
    3. //要有姣好的面孔
    4. public void goodLooking();
    5. //要有好身材
    6. public void niceFigure();
    7. //要有气质
    8. public void greatTemperament();
    9. }
    10. //接口的实现类
    11. public class PettyGirl implements IPettyGirl {
    12. private String name;
    13. public PettyGirl(String name){
    14. this.name= name;
    15. }
    16. //脸蛋漂亮
    17. public void goodLooking() {
    18. System.out.println(this.name + "---脸蛋很漂亮!");
    19. }
    20. //气质要好
    21. public void greatTemperament() {
    22. System.out.println(this.name + "---气质非常好!");
    23. }
    24. //身材要好
    25. public void niceFigure() {
    26. System.out.println(this.name + "---身材非常棒!");
    27. }
    28. }

    后来有些人的审美变了,不是特看中外表,外表一般,气质好,身材好的都称之为美女,那实现这个接口就不合理了

    1. public interface IGoodBodyGirl {
    2. //要有姣好的面孔
    3. public void goodLooking();
    4. //要有好身材
    5. public void niceFigure();
    6. }
    7. public interface IGreatTemperamentGirl {
    8. //要有气质
    9. public void greatTemperament();
    10. }
    11. public class PettyGirl implements IGoodBodyGirl,IGreatTemperamentGirl {
    12. private String name;
    13. public PettyGirl(String _name){
    14. this.name=_name;
    15. }
    16. //脸蛋漂亮
    17. public void goodLooking() {
    18. System.out.println(this.name + "---脸蛋很漂亮!");
    19. }
    20. //气质要好
    21. public void greatTemperament() {
    22. System.out.println(this.name + "---气质非常好!");
    23. }
    24. //身材要好
    25. public void niceFigure() {
    26. System.out.println(this.name + "---身材非常棒!");
    27. }
    28. }

    3、接口隔离原则使用时候的几个原则
    根据接口隔离原则拆分接口的时候,必须要先满足单一职责原则;
    提高高内聚:要求接口中尽量少公布public方法

    4、接口隔离原则与单一职责原则的区别
    单一职责原则要求类和接口职责单一,注重的是职责,是逻辑上的划分;
    而接口隔离原则是要求类和接口中的方法尽可能的少,是在接口设计上的考虑;