代理模式(C++)

#include 
using namespace std;

class surfinternet
{
public:
    surfinternet(){}
    virtual ~surfinternet(){}
    virtual void look_youtube()=0;
    virtual void look_twitter()=0;
    virtual void look_fackbook()=0;
};

class overwall : public surfinternet
{
public:
    overwall(){}
    virtual ~overwall(){}
    void look_youtube(){cout<<"look youtube"<<endl;}
    void look_twitter(){cout<<"look twitter"<<endl;}
    void look_fackbook(){cout<<"look facebook"<<endl;}
};

class proxy : public surfinternet
{
public:
    proxy(){psurfnet=new overwall;}
    virtual ~proxy(){delete psurfnet;}
    void look_youtube(){psurfnet->look_youtube();}
    void look_twitter(){psurfnet->look_twitter();}
    void look_fackbook(){psurfnet->look_fackbook();}

private:
    surfinternet *psurfnet;
};

int main()
{
    surfinternet *p=new proxy;
    p->look_youtube();
    p->look_twitter();
    p->look_fackbook();
    delete p;

    system("pause");
    return 0;
}

转载于:https://www.cnblogs.com/tiandsp/archive/2012/06/26/2564351.html

你可能感兴趣的:(代理模式(C++))