标签:
代理设计模式。此模式是用于serverclient排序。互联网接入,也经常使用的类代理,我觉得这种感觉很复杂。但是,这种设计模式本身是非常easy的。
是一类调用另一个类的功能。客户调用类,实际工作是由另一类完成。
式的代码:
#include <stdio.h>
class RealObj
{
public:
virtual void handleReq() = 0;
};
class DoSomething : public RealObj
{
public:
void handleReq()
{
puts("Actually, I will do the rest...");
}
};
class Proxy
{
RealObj *subject;
public:
Proxy(RealObj *sub) : subject(sub) {}
virtual ~Proxy()
{
if (subject) delete subject;
}
void request()
{
puts("Proxy request... using other object to requese.");
subject->handleReq();//Just simply call a function, using another object.
}
};
int main()
{
RealObj *sub = new DoSomething;
Proxy p(sub);
p.request();
return 0;
}
标签:
原文地址:http://www.cnblogs.com/gcczhongduan/p/4563011.html