Welcome to tiger's blog!

What lead to success, what we are seeking...
posts - 47, comments - 23, trackbacks - 0, articles - 8
   :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理

设计模式(Bridge)

Posted on 2007-04-13 09:49 tiger 阅读(324) 评论(0)  编辑 收藏 引用

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


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   博问   Chat2DB   管理