首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 其他教程 > 其他相关 >

Bridge Pattern 桥接器方式

2012-09-24 
Bridge Pattern 桥接器模式桥接器模式#include stdafx.h#include memory#include iostream#include

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;}


 

热点排行