[设计模式]适配器模式(Adapter)
来源:互联网 发布:数字网络意思大全 编辑:程序博客网 时间:2024/06/15 22:40
1.意图
将一个类的接口转换成客户希望的另外一个接口。Adapter模式使得原本由于接口不兼容而不能一起工作的那些类可以一起工作。
2.结构与参与者
3.代码示例
#include <iostream>#include <string>using namespace std;class Player{protected:string name;public:Player(string strName) { name = strName; }virtual void Attack()=0;virtual void Defense()=0;};class ChinesePlayer{protected:string name;public:ChinesePlayer(string strName) { name = strName; }virtual void ChineseAttack()=0;virtual void ChineseDefense()=0;};class ChineseCenter : public ChinesePlayer{public:ChineseCenter(string strName):ChinesePlayer(strName){}public:virtual void ChineseAttack(){cout<<name<<"中锋进攻"<<endl;}virtual void ChineseDefense(){cout<<name<<"中锋防守"<<endl;}};class Forwards : public Player{public:Forwards(string strName):Player(strName){}public:virtual void Attack(){cout<<name<<"前锋进攻"<<endl;}virtual void Defense(){cout<<name<<"前锋防守"<<endl;}};class Center : public Player{public:Center(string strName):Player(strName){}public:virtual void Attack(){cout<<name<<"中锋进攻"<<endl;}virtual void Defense(){cout<<name<<"中锋防守"<<endl;}};//为中锋翻译class TransLater: public Player{private:ChineseCenter *player;public:TransLater(string strName):Player(strName){player = new ChineseCenter(strName);}virtual void Attack(){player->ChineseAttack();}virtual void Defense(){player->ChineseDefense();}};//客户端int main(){Player *p=new TransLater("小李");p->Attack();return 0;}
- 设计模式----Adapter(适配器)
- 适配器设计模式(Adapter)
- 设计模式--适配器(Adapter)
- 适配器Adapter 设计模式
- 设计模式--Adapter(适配器)
- 设计模式 - 适配器(Adapter)
- 适配器设计模式-Adapter
- Adapter(适配器)设计模式
- Adapter-适配器设计模式
- 设计模式:adapter适配器
- 设计模式-----Adapter(适配器)模式
- 设计模式1-适配器模式(Adapter)
- 设计模式之--适配器模式(adapter)
- 设计模式之Adapter(适配器模式)
- 设计模式之适配器(Adapter)模式
- Java设计模式 - Adapter(适配器模式)
- 设计模式-适配器模式(Adapter Pattern)
- 设计模式之--适配器模式(adapter)
- C++ const用法
- 草根站长胖子讲述做站故事
- 一些开源项目网址
- PAIP.ecshop file_put_contents Warning notice解决方法
- linux下查看文件和文件夹大小
- [设计模式]适配器模式(Adapter)
- ListActivity源码分析
- Eclipse Preferences的设置
- 【转】Java:Session详解
- Juniper monitor interface
- webkit 详解
- modelsim error:'rom_nxm_tb' already exists and will be overwritten
- VC中DLL、OCX中获取本身完整路径
- POJ3041《Asteroids》方法:匈牙利算法(最小点覆盖数==最大二分匹配数)