码迷,mamicode.com
首页 > 其他好文 > 详细

Proxy Design Pattern 代理设计模式

时间:2015-06-09 13:17:23      阅读:120      评论:0      收藏:0      [点我收藏+]

标签:

代理设计模式。此模式是用于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;
}

执行:

技术分享



Proxy Design Pattern 代理设计模式

标签:

原文地址:http://www.cnblogs.com/gcczhongduan/p/4563011.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!