美文网首页
21.C++设计模式-代理模式

21.C++设计模式-代理模式

作者: 任振铭 | 来源:发表于2019-09-26 08:32 被阅读0次
    图片.png
    #define  _CRT_SECURE_NO_WARNINGS
    #include <iostream>
    using namespace std;
    
    class Protocol {
    public:
        virtual void sailBook() = 0;
    };
    
    class RealStore :public Protocol {
    public:
        virtual void sailBook() {
            cout<<"卖书"<<endl;
        }
    };
    
    class TaobaoProxy :public Protocol {
    public:
        Protocol* protocol;
        TaobaoProxy(Protocol* protocol) {
            this->protocol = protocol;
        }
        virtual void sailBook() {
            protocol->sailBook();
            cout << "淘宝代理卖书" << endl;
        }
    };
    
    void main() {
        RealStore* r = new RealStore;
        TaobaoProxy* t = new TaobaoProxy(r);
        t->sailBook();
        delete t;
        delete r;
        system("pause");
    }
    

    相关文章

      网友评论

          本文标题:21.C++设计模式-代理模式

          本文链接:https://www.haomeiwen.com/subject/norguctx.html