newwy
奋斗在IT路上的小蜗牛。一步一步往上爬,爬到小牛,在到大牛,然后是神牛,然后是犇,然后就可以离开IT行业,回归大自然了。 远离IT,珍爱生命!!! 记录学习的点滴。
/*********************************
*设计模式--装饰模式实现
*C++语言
*Author:WangYong
*Blog:http://www.cnblogs.com/newwy
********************************/
#include <iostream>
using namespace std;
class Component
{
	public:
	virtual ~Component(){}
	Component(){}
	virtual void Operation(){}
};
class ConcreteComponent:public Component
{
	public:
	ConcreteComponent(){}
	~ConcreteComponent(){}
	void Operation(){cout<<"ConcreteComponent operation ..."<<endl;}
};
class Decorator:public Component
{
	public:
	Decorator(Component*com){this->_com = com;}
	virtual ~Decorator(){}
	void Operation(){}
	protected:
	Component * _com;
};
class ConcreteDecrator:public Decorator
{
	public:
	ConcreteDecrator(Component*com):Decorator(com){}
	~ConcreteDecrator(){}
	void Operation(){_com->Operation();}
	void AddedBehavior(){cout<<"ConcreteDecrator::AddedBehavior..."<<endl;}
};
int main()
{
	Component*com = new ConcreteComponent();
	Decorator *dec = new ConcreteDecrator(com);
	dec->Operation();
	delete dec;
	return 0;
}

posted on 2010-10-18 23:51  newwy  阅读(284)  评论(0编辑  收藏  举报