zoukankan      html  css  js  c++  java
  • 接口隔离原则(ISP)

    接口隔离原则(ISP)

    接口隔离原则(Interface Segregation Principle)讲的是:使用多个专门的接口比使用单一的总接口总要好。换而言之,从一个客户类的角度来讲:一个类对另外一个类的依赖性应当是建立在最小接口上的。

    过于臃肿的接口是对接口的污染。不应该强迫客户依赖于它们不用的方法。

    My object-oriented umbrella(摘自Design Patterns Explained)

    Let me tell you about my great umbrella. It is large enough to get into! In fact, three or four other people can get in it with me. While we are in it, staying out of the rain, I can move it from one place to another. It has a stereo system to keep me entertained while I stay dry. Amazingly enough, it can also condition the air to make it warmer or colder. It is one cool umbrella.

    My umbrella is convenient. It sits there waiting for me. It has wheels on it so that I do not have to carry it around. I don't even have to push it because it can propel itself. Sometimes, I will open the top of my umbrella to let in the sun. (Why I am using my umbrella when it is sunny outside is beyond me!)

    In Seattle, there are hundreds of thousands of these umbrellas in all kinds of colors. Most people call them cars.

    实现方法:
    1、 使用委托分离接口
    2、 使用多重继承分离接口

                                                                                                                                                      原文作者   吕震宇

  • 相关阅读:
    c/c++指针数组和数组指针
    c/c++指针传参
    c/c++指针理解
    c/c++容器操作
    c/c++ 数组传参
    c/c++ 结构体传参问题
    c++ 创建对象的三种方法
    c/c++ 随机数生成
    c++预处理指令
    团队冲刺第二阶段01
  • 原文地址:https://www.cnblogs.com/EasyLive2006/p/658903.html
Copyright © 2011-2022 走看看