设计模式 之 《代理模式》

 

#ifndef __PROXY_MODEL_H__
#define __PROXY_MODEL_H__

#include <iostream>
using namespace std;

class Subject
{
    virtual void request() = 0;
};

class RealSubject : public Subject
{
public:
    void request(){ cout<<"真实的请求!"<<endl; }
};

class Proxy : public Subject
{
private:
    RealSubject* realSubject;
public:
    void request()
    {
        if(!realSubject)
            realSubject = new RealSubject();
        realSubject->request();
    }
};

#endif //__PROXY_MODEL_H__

/*
//《客户端》
#include "ProxyModel.h"

int _tmain(int argc, _TCHAR* argv[])
{
    Proxy* proxy = new Proxy();
    proxy->request();

    return 0;
}
*/

 

 

  

posted @ 2013-10-23 23:15  解放1949  阅读(148)  评论(0编辑  收藏  举报