设计模式(Bridge)

 

// Abstraction.h: interface for the CAbstraction class.
//
//

#if !defined(AFX_ABSTRACTION_H__EEDB1B76_5760_4067_A2CB_95604AE082E4__INCLUDED_)
#define AFX_ABSTRACTION_H__EEDB1B76_5760_4067_A2CB_95604AE082E4__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

class CAbstractionImp;

class CAbstraction 
{
public:
 CAbstraction(CAbstractionImp *pAbstrationImp);
 virtual ~CAbstraction();

protected:
 CAbstraction();

public:
 virtual void Func(void) = 0;

protected:
 CAbstractionImp *m_pAbstractionImp;

};

class CRefindedAbstraction : public CAbstraction
{
public:
 CRefindedAbstraction(CAbstractionImp *pAbstrationImp);
 virtual ~CRefindedAbstraction();

public:
 void Func(void);

};

#endif // !defined(AFX_ABSTRACTION_H__EEDB1B76_5760_4067_A2CB_95604AE082E4__INCLUDED_)

// Abstraction.cpp: implementation of the CAbstraction class.
//
//

#include "Abstraction.h"

#include "AbstractionImp.h"

//
// Construction/Destruction
//

CAbstraction::CAbstraction()
{

}

CAbstraction::CAbstraction(CAbstractionImp *pAbstractionImp)
{
 m_pAbstractionImp = pAbstractionImp;
}

CAbstraction::~CAbstraction()
{

}

/
CRefindedAbstraction::CRefindedAbstraction(CAbstractionImp *pAbstractionImp)
 : CAbstraction(pAbstractionImp)
{
 
}

CRefindedAbstraction::~CRefindedAbstraction()
{

}

void CRefindedAbstraction::Func()
{
 m_pAbstractionImp->Func();
}

// AbstractionImp.h: interface for the CAbstractionImp class.
//
//

#if !defined(AFX_ABSTRACTIONIMP_H__29762645_3054_47C4_BF33_D8DACB518CD5__INCLUDED_)
#define AFX_ABSTRACTIONIMP_H__29762645_3054_47C4_BF33_D8DACB518CD5__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

class CAbstractionImp 
{
public:
 CAbstractionImp();
 virtual ~CAbstractionImp();

public:
 virtual void Func(void) = 0;

};

class CAbstractionImpA : public CAbstractionImp
{
public:
 CAbstractionImpA();
 virtual ~CAbstractionImpA();

public:
 void Func(void);

};

class CAbstractionImpB : public CAbstractionImp
{
public:
 CAbstractionImpB();
 virtual ~CAbstractionImpB();

public:
 void Func(void);

};

#endif // !defined(AFX_ABSTRACTIONIMP_H__29762645_3054_47C4_BF33_D8DACB518CD5__INCLUDED_)

// AbstractionImp.cpp: implementation of the CAbstractionImp class.
//
//

#include "AbstractionImp.h"
#include <iostream>
using namespace std;

//
// Construction/Destruction
//

CAbstractionImp::CAbstractionImp()
{

}

CAbstractionImp::~CAbstractionImp()
{

}

/
CAbstractionImpA::CAbstractionImpA()
{

}

CAbstractionImpA::~CAbstractionImpA()
{

}

void CAbstractionImpA::Func()
{
 cout<<"CAbstractionImpA::Func"<<endl;
}

/
CAbstractionImpB::CAbstractionImpB()
{

}

CAbstractionImpB::~CAbstractionImpB()
{

}

void CAbstractionImpB::Func()
{
 cout<<"CAbstractionImpB::Func"<<endl;
}

//main
#include "Abstraction.h"
#include "AbstractionImp.h"

void main()
{
 CAbstractionImp *pAbstractionImp = new CAbstractionImpB();
 CAbstraction *pAbstraction = new CRefindedAbstraction(pAbstractionImp);
 pAbstraction->Func();
 delete pAbstraction;
 delete pAbstractionImp;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值