class Target { public: virtual void Request(){}; };
class Adaptee { public: void SpecificRequest() { cout<<"SpecificRequest"<<endl; } };
class Adapter : public Adaptee, public Target//多重继承自目标接口和需要适配的类 { public: void Request() { this->SpecificRequest(); } };
class Adapter : public Target { private: Adaptee *adaptee=new Adaptee(); public: void Request() { adaptee->SpecificRequest();//含有一个实际接口的实例 } };
int main() { Target *target = new Adapter(); target->Request(); return 0; }
原文地址:http://blog.csdn.net/zsp_skyer/article/details/28694571