Bridge Pattern 桥接器模式
桥接器模式
#include "stdafx.h"#include <memory>#include <iostream>#include <vld.h>using namespace std;using namespace tr1;//The implement of bridge pattern//which can make the variable of the abstract and its implement seperately.class Implementor{public:virtual void operationImpl() = 0;virtual ~Implementor(){}};class ConcreteImplementor : public Implementor{public:void operationImpl(){cout<<"The function ....."<<endl;}};class Abstract{public:Abstract(Implementor* pImp):m_ptr(pImp){}virtual void operation() = 0;virtual ~Abstract(){}protected:shared_ptr<Implementor> m_ptr;};class ConcreteAbstract : public Abstract{public:ConcreteAbstract(Implementor* pImp):Abstract(pImp){}void operation(){m_ptr->operationImpl();}};int _tmain(int argc, _TCHAR* argv[]){shared_ptr<Abstract> pobj(new ConcreteAbstract(new ConcreteImplementor));pobj->operation();return 0;}