Adapter设计模式
来源:互联网 发布:学不会javascript 编辑:程序博客网 时间:2024/05/22 05:24
#include <iostream>#define CCLASSclass Target{public:virtual void Request(){};};class Adaptee{public:void SpecificRequest(){std::cout<<"SpecificRequest"<<std::endl;};}; #ifdef CCLASS // calss pattern class Adapter: public Target, private Adaptee{public:void Request(){SpecificRequest();}};#else class Adapter:public Target //Object pattern {public:Adapter(Adaptee* ade);~Adapter();virtual void Request();private:Adaptee* _ade;};Adapter::Adapter(Adaptee* ade){this->_ade=ade;}void Adapter::Request(){_ade->SpecificRequest();}#endifint main(int argc, char* argv[]){#ifdef CCLASSTarget* p=new Adapter();p->Request();#elseAdaptee* ade=new Adaptee;Target* adt=new Adapter(ade);adt->Request();#endifreturn 0;}
分为类模式和对象模式
类模式主要是Adapter同时继承Target和Adaptee
然后用函数把Adapter的需求转换为Adaptee
对象模式主要是Adapter继承Target, 然后包含Adaptee
通过Adapter的私有Adaptee× 指向包含进来的Adaptee×,
通过函数, Adapter的需求为私有Adaptee*的需求,私有Adaptee*的需求指向包含进来的私有Adaptee*的需求
0 0
- 设计模式---Adapter模式
- 设计模式---Adapter模式
- 设计模式---Adapter模式
- 设计模式-Adapter模式
- 设计模式 - Adapter模式
- Adapter设计模式
- 设计模式--Adapter
- 设计模式之 Adapter
- 设计模式(Adapter)
- 设计模式-Adapter
- 设计模式之Adapter
- 设计模式--适配器(Adapter)
- Adapter设计模式
- 设计模式之Adapter
- 设计模式之ADAPTER
- C++设计模式 Adapter
- 适配器Adapter 设计模式
- C++设计模式-Adapter
- An intro to modern OpenGL. Chapter 3: 3D transformation and projection
- Android 中自定义控件和属性(attr.xml,declare-styleable,TypedArray)的方法和使用
- PHP学习随笔
- 多线程异步处理:AsyncTask异步更新UI界面 android开发教程
- 不允许保存更改。您所做的更改要求删除并重新创建以下表。您对无法重新创建的标进行了更改或者启用了“阻止保存要求重新创建表的更改
- Adapter设计模式
- 屋面瓦的五大分类及区别
- 最近很流行爸爸去哪儿吗?
- 交叉编译器 arm-linux-gnueabi 和 arm-linux-gnueabihf 的区别
- Redhat 6.3中syslog信息丢失
- tcpdump命令
- hadoop2.2.0 关于hdfs的梳理
- Web Secret:图片服务(一)——构建一个基本的图片服务
- 我很喜欢这部电视