设计模式 - Adapter
意图:将一个类的接口转换成客户希望的另外一个接口,使得原本由于接口不兼容而不能一起工作的那些类可以一起工作。
class Target { public: Target() {} virtual ~Target() {} virtual void Request() { cout<<"Target::Request()"<<endl; } }; class Adaptee { public: Adaptee() {} ~Adaptee() {} void SpecificRequest() { cout<<"Adaptee::SpecificRequest()"<<endl; } }; class Adapter: public Target { public: Adapter() { this->adaptee = new Adaptee(); } ~Adapter() { if(this->adaptee != NULL) { delete this->adaptee; } } void Request() { adaptee->SpecificRequest(); } private: Adaptee* adaptee; };