資源簡介
適配器模式 設(shè)計模式 Adapter
還請各位大S指教
代碼片段和文件信息
#include?
using?namespace?std;
/*
適配器模式?實例
核心:大規(guī)模使用新接口,并為了兼容以往接口時,本模式適用。
??作者:離開的思緒
??時間:2012-11-21
*/
/************************************************************/
class?NewInterface
{
public:
virtual?void?NewAction()=0;
};
class?OldInterFace
{
public:
void?OldAction()
{
cout<<“我其實是老方法!“< }
};
/************************************************************/
//?適配器繼承于新接口提供類,并擁有一個舊接口成員
class?Adapter:public?NewInterface
{
public:
OldInterFace?m_pOi;
virtual?void?NewAction()
{
m_pOi.OldAction();
}
};
/************************************************************/
int?main()
{
NewInterface?*p?=?new?Adapter();
p->NewAction(); //?雖然使用新接口,但是實際上調(diào)用了舊接口的方法
delete?p;
p?=?NULL;
return?0;
}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件????????863??2012-11-21?11:49??DesignMode_Adapter\DesignMode_Adapter.cpp
?????文件???????4428??2012-11-21?11:45??DesignMode_Adapter\DesignMode_Adapter.dsp
?????文件????????561??2012-11-21?11:33??DesignMode_Adapter\DesignMode_Adapter.dsw
?????文件??????41984??2012-11-21?11:50??DesignMode_Adapter\DesignMode_Adapter.ncb
?????文件??????53760??2012-11-21?11:50??DesignMode_Adapter\DesignMode_Adapter.opt
?????文件???????1410??2012-11-21?11:50??DesignMode_Adapter\DesignMode_Adapter.plg
?????目錄??????????0??2012-11-21?11:53??DesignMode_Adapter
-----------?---------??----------?-----??----
???????????????103006????????????????????7
- 上一篇:實現(xiàn)unix虛擬文件系統(tǒng)
- 下一篇:算術(shù)編碼C++
評論
共有 條評論