代理模式(C++)

#include <iostream>
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;
}
posted @ 2012-06-26 21:03  Dsp Tian  阅读(547)  评论(0编辑  收藏  举报