Bridge (C++实现)

// Bridge.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include <iostream>

using namespace std;

class Implementor
{
public:
  Implementor()
  {
  }
  virtual ~ Implementor()
  {
  }
  virtual void OperationImp()=0;
};

class ConcreteImpleteorA:public Implementor
{
public:
  ConcreteImpleteorA()
  {
   cout<<"Construction of  ConcreteImpleteorA"<<endl;
  }

  virtual ~ ConcreteImpleteorA()
  {
    cout<<"Destruction of  ConcreteImpleteorA"<<endl;
  }
  virtual void OperationImp()
  {
   cout<<"Operation of ConcreteImpleteorA"<<endl;
  }

};
class ConcreteImpleteorB:public Implementor
{
 public:
  ConcreteImpleteorB()
  {
   cout<<"Construction of  ConcreteImpleteorB"<<endl;
  }

  virtual ~ ConcreteImpleteorB()
  {
    cout<<"Destruction of  ConcreteImpleteorB"<<endl;
  }
  virtual void OperationImp()
  {
   cout<<"Operation of ConcreteImpleteorB"<<endl;
  }

};

 

////////////////////////////////////////////////////////////

 

class Abstraction
{
public:
 Abstraction(Implementor * m_p):m_pImplementor(m_p){}
 virtual ~ Abstraction()
 {
  delete m_pImplementor;
  m_pImplementor=NULL;
 }
 void Operation()
 {
  m_pImplementor->OperationImp();
 }

private:
 Implementor * m_pImplementor;
};

 

int _tmain(int argc, _TCHAR* argv[])
{
 ConcreteImpleteorA *p_ConcreteImpleteorA=new ConcreteImpleteorA();
 Abstraction *p_Abstraction=new Abstraction(p_ConcreteImpleteorA);
 p_Abstraction->Operation();
 delete p_Abstraction;

 return 0;
}

 

posted on 2011-05-23 17:08  IT@民工  阅读(231)  评论(0编辑  收藏  举报

导航