设计模式 之 《代理模式》
#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; } */
Dreams are one of those things that keep you going and happy!!!