#ifndef __ADAPTER_MODEL__ #define __ADAPTER_MODEL__ #include <iostream> using namespace std; //GOOD:双方都不适合修改的时候,可以考虑使用适配器模式 class Target { public: virtual void request(){ cout<<"普通的请求"<<endl; } }; class Adaptee { public: void specificalRequest(){ cout<<"特殊请求"<<endl; } }; class Adapter : public Target { private: Adaptee* adapt; public: Adapter(){ adapt = new Adaptee(); } ~Adapter(){ delete adapt; } virtual void request() { adapt->specificalRequest(); Target::request(); } }; #endif //__ADAPTER_MODEL__ /* #include "Adapter.h" int _tmain(int argc, _TCHAR* argv[]) { Adapter* ada = new Adapter(); ada->request(); delete ada; return 0; } */