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 首先我们来面 ...
随机推荐
- P5212 SubString LCT+SAM
$ \color{#0066ff}{ 题目描述 }$ 给定一个字符串init,要求支持两个操作 在当前字符串的后面插入一个字符串 询问字符串ss在当前字符串中出现了几次?(作为连续子串) 强制在线. ...
- P3943 星空 区间异或差分
\(\color{#0066ff}{ 题目描述 }\) 逃不掉的那一天还是来了,小 F 看着夜空发呆. 天上空荡荡的,没有一颗星星--大概是因为天上吹不散的乌云吧. 心里吹不散的乌云,就让它在那里吧, ...
- C++基础学习8:类的定义(class)
先来说说C和C++中结构体的不同 a) C语言中的结构体不能为空,否则会报错(??) b) C语言中内存为空结构体分配大小为0,C++中为结构体和类分配大小为1byte c) C语言中的结构体只涉及到 ...
- C# 实现retry
C# 有try-catch ,但是没有retry 功能,通过用有限次循环的办法来模拟Retry,当然中间需要加一个等待的过程. 我们可以利用C#的匿名方法(anonymous methods)和匿名委 ...
- Codeforces Round #526 (Div. 2) D. The Fair Nut and the Best Path 树上dp
D. The Fair Nut and the Best Path 题意:给出一张图 点有权值 边也要权值 从任意点出发到任意点结束 到每个点的时候都可以获得每个点的权值,而从边走的时候都要消耗改边的 ...
- Unity 动画系统 StateMachineBehaviour 动画状态机
- C语言讲解命令行参数
命令行(command line):是在命令行环境中,用户为运行程序输入命令的行. 命令行参数(command-line argument): 是同一行的附加项. C编译器允许main()没有参数或者 ...
- sharepoint_study_目录学习笔记(长期更新)
1. _catalogs/masterpage:这个是SharePoint网站的母版页样式库页面,这里放了网站上所有的母版页(网站设置--Web设计器库--母版页和页面布局). 2. 15\TEMP ...
- BFS + 状态搜索
题目 题意 给一个100x100的迷宫,'.'表示路面,'S'表示起点,'T'表示终点:'#'表示毒气区,进入毒气区必须要消耗一个氧气:'B'表示氧气区,每次进入自动获得一个氧气,可反复进入从而获得多 ...
- 2016"百度之星" - 资格赛(Astar Round1)D
Problem Description 度熊所居住的 D 国,是一个完全尊重人权的国度.以至于这个国家的所有人命名自己的名字都非常奇怪.一个人的名字由若干个字符组成,同样的,这些字符的全排列的结果中的 ...