/* object_adapter.cpp * * Adapter objects get their functionality through an association * with an Adaptee object. */ #include #include class Interface { public: virtual void request() = 0; }; class Target { public: virtual void specificRequest() {std::cout << "Using specific request\n";} }; class Adapter: public Interface { public: Adapter(Target* target) : adaptee(target) {} virtual void request(){ adaptee->specificRequest(); } private: Target* adaptee; }; class Client { public: Client(Interface* interface) : _interface(interface) {} void do_something() { _interface->request(); } private: Interface* _interface; }; int main() { Target t; Adapter a(&t); Client client(&a); client.do_something(); }