/********************************* *设计模式--桥接模式实现 *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; }