设计模式之适配器模式(Adapter)
来源:互联网 发布:cst仿真软件如何 编辑:程序博客网 时间:2024/06/07 23:32
优点:1)使用已存在的类,接口不符合要求
2)创建复用的类,该类可以与其它不相关的类协同工作
#include <iostream>using namespace std;class Target{public: virtual void Interface() = 0;};class Adapter{public: void SpecificInterfaceA(){ cout<<"Called SpecificInterfaceA"<<endl;} void SpecificInterfaceB(){ cout<<"Called SpecificInterfaceB"<<endl;}};class AdapterClassA : public Target, public Adapter{public: void Interface(){SpecificInterfaceA();}};class AdapterClassB : public Target{public: AdapterClassB(){_adapter = new Adapter;} void Interface(){_adapter->SpecificInterfaceB();}private: Adapter *_adapter;};int main(){ Target *targetA = new AdapterClassA; targetA->Interface(); Target *targetB = new AdapterClassB; targetB->Interface(); return 0;}
运行结果:
Called SpecificInterfaceA
Called SpecificInterfaceB
阅读全文
0 0
- 设计模式之适配器-Adapter--适配器模式
- 设计模式之Adapter(适配器)
- 设计模式之Adapter(适配器)
- 设计模式之Adapter(适配器)
- 设计模式之Adapter(适配器)
- 设计模式之Adapter(适配器)
- 设计模式之Adapter(适配器)
- 设计模式之Adapter(适配器)
- 设计模式之Adapter(适配器)
- 设计模式之Adapter(适配器)
- 设计模式之Adapter(适配器)
- 设计模式之Adapter(适配器)
- 设计模式之Adapter(适配器)
- 设计模式之Adapter(适配器)
- 设计模式之Adapter(适配器)
- 设计模式之Adapter(适配器)
- 设计模式之Adapter(适配器)
- 设计模式之适配器-Adapter
- idea部署iBase4J
- js关于继承
- 怎么进入到adb shell命令
- 搬瓦工搭建Shadowsocks和优化速度详细图文教程
- Spearman
- 设计模式之适配器模式(Adapter)
- 英文论文写作心得
- vim 打开二进制文件
- VS2010 常用快捷键 看到不错,收了
- 调试Js的利器
- CSS布局奇淫巧计之-强大的负边距
- ajax提交表单的信息的正确使用
- 97. Interleaving String
- C语言 链表 求某班20名学生的最高成绩