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;
}

 

posted @ 2014-12-10 14:25  stanley19861028  阅读(119)  评论(0编辑  收藏  举报