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的更多相关文章

  1. Design Pattern Adaptor 适配器设计模式

    适配器设计模式是为了要使用一个旧的接口,或许这个接口非常难用,或许是和新的更新的接口不兼容,所以须要设计一个适配器类,然后就能够让新旧的接口都统一. 就是这种一个图: watermark/2/text ...

  2. 说说设计模式~大话目录(Design Pattern)

    回到占占推荐博客索引 设计模式(Design pattern)与其它知识不同,它没有华丽的外表,没有吸引人的工具去实现,它是一种心法,一种内功,如果你希望在软件开发领域有一种新的突破,一个质的飞越,那 ...

  3. 设计模式(Design Pattern)系列之.NET专题

    最近,不是特别忙,重新翻了下设计模式,特地在此记录一下.会不定期更新本系列专题文章. 设计模式(Design pattern)是一套被反复使用.多数人知晓的.经过分类编目的.代码设计经验的总结. 使用 ...

  4. [转]Design Pattern Interview Questions - Part 4

    Bridge Pattern, Composite Pattern, Decorator Pattern, Facade Pattern, COR Pattern, Proxy Pattern, te ...

  5. [转]Design Pattern Interview Questions - Part 2

    Interpeter , Iterator , Mediator , Memento and Observer design patterns. (I) what is Interpreter pat ...

  6. [转]Design Pattern Interview Questions - Part 3

    State, Stratergy, Visitor Adapter and fly weight design pattern from interview perspective. (I) Can ...

  7. [转]Design Pattern Interview Questions - Part 1

    Factory, Abstract factory, prototype pattern (B) What are design patterns? (A) Can you explain facto ...

  8. design pattern

    1. visitor design pattern http://butunclebob.com/ArticleS.UncleBob.IuseVisitor

  9. Design Pattern: Observer Pattern

    1. Brief 一直对Observer Pattern和Pub/Sub Pattern有所混淆,下面打算通过这两篇Blog来梳理这两种模式.若有纰漏请大家指正. 2. Use Case 首先我们来面 ...

随机推荐

  1. 模板 Trie树

    模板 Trie树 code: #include <iostream> #include <cstdio> using namespace std; const int wx=2 ...

  2. Maven入门(二)pom.xml和核心概念

    一.pom.xml文件说明 1.pom意思就是project object model. 2.pom.xml包含了项目构建的信息,包括项目的信息.项目的依赖等. 3.pom.xml文件是可以继承的,大 ...

  3. DRF教程7-token认证

    Authentication 认证是将一个传入的请求和一组标识凭据相关联的机制,比如请求过来的用户,或者用户登录时携带的token. 然后权限策略就能使用这些凭据来决定是否允许这个请求. REST框架 ...

  4. 【Ant】How to print all the system properties in Ant build file

    在Ant里可以使用echoproperties task来达到目的 <target name="run"> <echoproperties /> </ ...

  5. hdu1686 KMP 求在字符串A中字符串B出现的次数

    Oulipo Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Subm ...

  6. centos 7 安装 最小化 碰到的问题

    1)分区推荐 2)更新yum源  (收藏 https://mirror.webtatic.com/yum/el7/) cd /etc/yum.repos.d/ 更新源 wget http://mirr ...

  7. mysqldump的用法

    1.mysqldump 是文本备份还是二进制备份 它是文本备份,如果你打开备份文件你将看到所有的语句,可以用于重新创建表和对象.它也有 insert 语句来使用数据构成表. mysqldump可产生两 ...

  8. beeline hiveserver2 start

    1. install hive 2. start hiveserver2 查看hiverserver2 是否正常运行: ps -ef | grep hive 2. start beeline 3. 链 ...

  9. python3 pip使用报错

     在windodws上pip3使用了很长时间,今天突然报错. Fatal error in launcher: Unable to create process using '"' 解决方案 ...

  10. 使用Ext 创建树

    ext使用的是ext3.4.0版本 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> < ...