概念
    客户端不应该依赖他不需要的接口;一个类对另一个类的依赖建立在最小的接口上。

    思路

    1. 定义接口时,尽量减少接口的方法和属性。
    2. 类在实现某个接口时,不要为了实现该接口,被迫地定义一些无用的方法或属性。
    3. 可以把多个类依赖的接口分成多个小接口,类实现接口时,可以同时实现多个小接口,这样就完成了接口的隔离,灵活性也高。

    代码实现

    1. <?php
    2. interface E
    3. {
    4. public function func1();
    5. }
    6. interface F
    7. {
    8. public function func2();
    9. public function func3();
    10. }
    11. interface G
    12. {
    13. public function func4();
    14. public function func5();
    15. public function func6();
    16. }
    17. class A implements E,F
    18. {
    19. public function func1()
    20. {
    21. // TODO: Implement func1() method.
    22. }
    23. public function func2()
    24. {
    25. // TODO: Implement func2() method.
    26. }
    27. public function func3()
    28. {
    29. // TODO: Implement func3() method.
    30. }
    31. }
    32. class B implements F
    33. {
    34. public function func2()
    35. {
    36. // TODO: Implement func2() method.
    37. }
    38. public function func3()
    39. {
    40. // TODO: Implement func3() method.
    41. }
    42. }
    43. class C implements G
    44. {
    45. public function func4()
    46. {
    47. // TODO: Implement func4() method.
    48. }
    49. public function func5()
    50. {
    51. // TODO: Implement func5() method.
    52. }
    53. public function func6()
    54. {
    55. // TODO: Implement func6() method.
    56. }
    57. }