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