Design Pattern ->Adaptor
Layering & Contract Philosophy With additional indirection
Adaptee object just is as a member. Adaptee object just relies on Adapter object.
class CAdaptee
{
public: void theExistingAndIncompatibleMethod(){ … } ;
}
class CTarget
{
public: virtual void theNewMethod() = ;
} class CAdapter: public CTarget, CAdaptee
{
public: void theNewMethod()
{
this->theExistingAndIncompatibleMethod();
};
} class CAdapter: public CTarget
{
public: void theNewMethod()
{
CAdaptee object;
object.theExistingAndIncompatibleMethod();
};
}
class client
{
public: void operation()
{
CTarget *pTarget = new CAdapter; pTarget->theNewMethod();}
}
Applicability
Use the Adapter pattern when
- you want to use an existing class having a incompatible method with the new interface from the one you want to use, and its interface does not match the one you need. You want to create a reusable class that cooperates with unrelated or unforeseen classes, that is, classes that don't necessarily have compatible interfaces.
- (object adapter only) you need to use several existing subclasses, but it's impractical to adapt their interface by subclassing/making as subclass every one. An object adapter can adapt the interface of its parent class.
Participants
- Target (Shape): defines the domain-specific interface that Client uses.
- Client (DrawingEditor): collaborates with objects conforming to the Target interface.
- Adaptee (TextView): defines an existing interface that needs adapting.
- Adapter (TextShape): adapt the interface of Adaptee to the Target interface.
Collaborations
- Clients call operations on an Adapter instance. In turn, the adapter calls Adaptee operations that carry out the request.
Design Pattern ->Adaptor的更多相关文章
- Design Pattern Adaptor 适配器设计模式
适配器设计模式是为了要使用一个旧的接口,或许这个接口非常难用,或许是和新的更新的接口不兼容,所以须要设计一个适配器类,然后就能够让新旧的接口都统一. 就是这种一个图: watermark/2/text ...
- 说说设计模式~大话目录(Design Pattern)
回到占占推荐博客索引 设计模式(Design pattern)与其它知识不同,它没有华丽的外表,没有吸引人的工具去实现,它是一种心法,一种内功,如果你希望在软件开发领域有一种新的突破,一个质的飞越,那 ...
- 设计模式(Design Pattern)系列之.NET专题
最近,不是特别忙,重新翻了下设计模式,特地在此记录一下.会不定期更新本系列专题文章. 设计模式(Design pattern)是一套被反复使用.多数人知晓的.经过分类编目的.代码设计经验的总结. 使用 ...
- [转]Design Pattern Interview Questions - Part 4
Bridge Pattern, Composite Pattern, Decorator Pattern, Facade Pattern, COR Pattern, Proxy Pattern, te ...
- [转]Design Pattern Interview Questions - Part 2
Interpeter , Iterator , Mediator , Memento and Observer design patterns. (I) what is Interpreter pat ...
- [转]Design Pattern Interview Questions - Part 3
State, Stratergy, Visitor Adapter and fly weight design pattern from interview perspective. (I) Can ...
- [转]Design Pattern Interview Questions - Part 1
Factory, Abstract factory, prototype pattern (B) What are design patterns? (A) Can you explain facto ...
- design pattern
1. visitor design pattern http://butunclebob.com/ArticleS.UncleBob.IuseVisitor
- Design Pattern: Observer Pattern
1. Brief 一直对Observer Pattern和Pub/Sub Pattern有所混淆,下面打算通过这两篇Blog来梳理这两种模式.若有纰漏请大家指正. 2. Use Case 首先我们来面 ...
随机推荐
- EOS 增发与生产者的奖励制度
EOS每年增发1%的机制在系统合约中,其实说每年增发1%只是一年的总数,其实是只要在出块,EOS就在增发的路途中,下面分析一下增发的代码. 其实增发的1%的都是分给所有区块生产者的,只要出块了或者获得 ...
- 09. ajax跨域问题,同源策略
有三个标签允许跨域加载资源 <img src=“”/> <link href=“”/> <script src=“”> 可以做防盗链图片功能 前端使用jsonp ...
- 深浅copy 和 集合
1 对于赋值运算,就是共同指向一个内存地址.将一个值赋予一个变量,那么它的内存地址同时也赋予了他,如果值是不可变类型,改变值,就会产生一个新值和新内存地址,如果值是可变类型那么内存地址不会变. s1 ...
- 001 开发环境搭建、安卓项目结构、R文件位置、asset目录创建
1.安卓开发平台搭建 (1)下载SDK基础工具包(自己的百度云中) (2)将下载的安装包(android-sdk_r24.4.1-windows.zip)解压后,放到以下路径 C:\SoftAppli ...
- Should I buy Auro OtoSys IM600 or Obdstar X300 DP?
Auro OtoSys IM600 and Obdstar X300 DP – What’s the difference & Which better? This is for those ...
- 时间戳date 命令
时间戳date 命令 [chenxiaohao@iZbp1c0q444r0hp2gq8lhmZ server]$ echo $(date +%Y%m%d) ——————>今天 2018032 ...
- OS---文件结构
1.概述 1.1 对于任何一个文件,都存在以下2种形式结构: 文件的逻辑结构: 从用户的角度出发所观察到的文件组织形式,独立于文件的物理特性: 文件的物理结构(文件存储结构): 文件在外存上的存储组织 ...
- plSql添加快捷键设置
汉化版:工具-首选项-用户界面-编辑器-自动替换-定义文件 英文版:Tools->Perferences->Editor中Autoreplaces选择配置的shortcuts 常用快捷键设 ...
- JAVA中的for循环
在Java程序中,要“逐一处理”――或者说,“遍历”――某一个数组或Collection中的元素的时候,一般会使用一个for循环来实现(当 然,用其它种类的循环也不是不可以,只是不知道是因为for这个 ...
- android window(二)从getSystemService到WindowManagerGlobal
在Activity调用getSystemService(WINDOW_SERVICE) 调用的是父类ContextThemeWrapper package android.view; public c ...