首页 > 代码库 > Adapter

Adapter

#include <iostream>using namespace std;class ThirdPartImpl{public:    void SomeFunction() { cout<<"ThirdPartImpl::SomeFunction"<<endl; }};class Target{public:    virtual void SomeRequest()=0;};class Adapter : public Target{public:    Adapter() { m_pImpl = new ThirdPartImpl; }    ~Adapter() { delete m_pImpl; }    void SomeRequest() { m_pImpl->SomeFunction(); }    private:    ThirdPartImpl* m_pImpl;};int main(int argc, char *argv[]){    Target* pTarget = new Adapter;    pTarget->SomeRequest();    delete pTarget;    pTarget = NULL;    return 0;}

 

Adapter