bridge橋接模式
阿新 • • 發佈:2019-01-29
#include <iostream> #include <string> using namespace std; class abstraction_imp { public: virtual ~abstraction_imp(){} virtual void operation() =0; }; class abstraction { public: virtual ~abstraction(){} virtual void operation() =0; protected: abstraction(){} }; class refined_abstraction : public abstraction { public: refined_abstraction(abstraction_imp *imp):_imp(imp){} void operation() { _imp->operation(); } private: abstraction_imp *_imp; }; class concrete_abstraction_impA : public abstraction_imp { public: void operation() { cout << "concrete_abstraction_impA::operation"<<endl; } }; class concrete_abstraction_impB : public abstraction_imp { public: void operation() { cout << "concrete_abstraction_impB::operation"<<endl; } }; int main() { abstraction *a = new refined_abstraction(new concrete_abstraction_impB); a->operation(); delete a; return 0; }