设计模式-结构-Proxy(代理)模式
访问的中间媒介。Proxy模式最大的好处就是实现了逻辑和实现的彻底解耦
- 远程代理
- 虚代理
- 保护代理
- 智能指针
结构图
class SubObject { public: virtual void Request() = 0; }; class ConCreateSubObject :public SubObject { public: virtual void Request()override { } }; class Proxy { public: void Request() { sub->Request(); //do something else } Proxy(SubObject *sub) { this->sub = sub; } private: SubObject *sub; }; int main(int argc, char *argv[]) { Proxy *proxy = new Proxy(new ConCreateSubObject); proxy->Request(); system("pause"); return 0; }