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