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 首先我们来面 ...
随机推荐
- UDP socket
1.Udp :User Datagram Protocol(Udp)用户数据报文协议. 2.适用于局域网的主机间通信. 3.使用方法 1:创建Socket OS_Socket local(127.0. ...
- SP18637 LAWRENCE - Lawrence of Arabia
\(\color{#0066ff}{ 题目描述 }\) 给定一个长度为n的序列,至多将序列分成m+1段,每段序列都有权值,权值为序列内两个数两两相乘之和.求序列权值和最小为多少? \(\color{# ...
- NOIP2018初赛总结(提高组)(试题+答案+简要解析)
NOIP2018初赛总结(提高组) 更新完毕(纯手敲),如果有错误请在下面留言 单选题 T1.下列四个不同进制的数中,与其它三项数值上不相等的是 A.\((269)_{16}\) B.\((617)_ ...
- atcoder 2579
You are taking a computer-based examination. The examination consists of N questions, and the score ...
- CF796C Bank Hacking 思维
Although Inzane successfully found his beloved bone, Zane, his owner, has yet to return. To search f ...
- 04->python字典
字典dict 1.数据类型分类(按可变和不可变) 不可变数据类型:数字.bool.str.tuple 可变数据类型:list.dict.set 2.dict的组成 key:va ...
- mysql 模糊查询 concat()
concat() 函数,是用来连接字符串. 精确查询: select * from user where name=”zhangsan” 模糊查询: select * from user where ...
- nodejs創建目錄命令mkdir失敗
Windows系統 學習nodejs創建目錄命令:mkdir var fs = require('fs'); fs.mkdir('./tmp/test',function (err) { if(err ...
- pandas学习2(基础操作)
- 浅谈APP消息推送
作为移动端APP产品运营最重要的运营手段,消息推送(push)被越来越多的APP厂商所重视,在信息泛滥的移动互联网时代,手机APP应用安装得越来越多,小小的手机屏幕每天收到的消息推送也越来越多,站在用 ...