newwy
奋斗在IT路上的小蜗牛。一步一步往上爬,爬到小牛,在到大牛,然后是神牛,然后是犇,然后就可以离开IT行业,回归大自然了。 远离IT,珍爱生命!!! 记录学习的点滴。
/*********************************
*设计模式--桥接模式实现
*C++语言
*Author:WangYong
*Blog:http://www.cnblogs.com/newwy
********************************/
#include <iostream>
using namespace std;

class AbstractionImp
{
	public:
	virtual ~AbstractionImp(){}
	virtual void Operation() = 0;
	AbstractionImp(){}
}; 
void AbstractionImp::Operation(){cout<<"AbstractImp ... imp"<<endl;}

class Abstraction
{
	public:
	virtual ~Abstraction(){}
	virtual void Operation() = 0;
	Abstraction(){}
};
class RefinedAbstraction:public Abstraction
{
	public:
	RefinedAbstraction(AbstractionImp *imp){_imp = imp;}
	~RefinedAbstraction(){}
	void Operation(){_imp->Operation();}
	private:
	AbstractionImp *_imp;
};

class ConcreteAbstractionImpA:public AbstractionImp
{
	public:
	ConcreteAbstractionImpA(){}
	~ConcreteAbstractionImpA(){}
	virtual void Operation(){cout<<"ConcreteAbstractorImpA...."<<endl;}
};
class ConcreteAbstractionImpB:public AbstractionImp
{
	public:
	ConcreteAbstractionImpB(){}
	~ConcreteAbstractionImpB(){}
	virtual void Operation(){cout<<"ConcreteAbstractorImpB...."<<endl;}
};
int main()
{
	AbstractionImp *imp = new ConcreteAbstractionImpA();
	Abstraction *abs = new RefinedAbstraction(imp);
	abs->Operation();
	return 0;
}

posted on 2010-10-18 23:45  newwy  阅读(400)  评论(2编辑  收藏  举报