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. POI精确设置Excel的行高和列宽

    EXCEL的行高度和列宽度单位是不一样的. 1,EXCEL列高度的单位是磅,Apache POI的行高度单位是缇(twip): 1英寸=72磅=25.4毫米=1440缇1磅=0.353毫米=20缇 P ...

  2. 最长回文串:LeetCode:Longest Palindromic Substring

    class Solution { public: string longestPalindrome(string s) { int length=s.length(); ; ; ][]={false} ...

  3. sharepoint_study_6

    描述:SharePoint 2013配置开发环境,需要安装VS2012插件 解决: 参见地址-http://www.java123.net/detail/view-330510.html

  4. P3800 Power收集

    传送门 DP每次向下一格,显然是DP方程也十分显然:设$f[i][j]$为到第$i$行第$j$列时能得到的最大价值显然$f[i][j]=max(f[i-1][k]+v[i][j]),( max(0,j ...

  5. html一些常用的符号

    <    :    < >    :    > &    :    & "     :    " @   :    © ®    :     ...

  6. zabbix 安装使用

    zabbix是一个基于WEB界面的提供分布式系统监视以及网络监视功能的企业级的开源解决方案. zabbix能监视各种网络参数,保证服务器系统的安全运营:并提供灵活的通知机制以让系统管理员快速定位/解决 ...

  7. Storm(1)-centos7下安装单机版Strom

    1.所需软件: jdk8.zookeeper.storm 2.安装zookeeper单机版 下载:http://zookeeper.apache.org/releases.html#download ...

  8. python 中is和= = 的区别

    Python中的对象包含三要素:id.type.value,其中id用来唯一标识一个对象,type标识对象的类型,value是对象的值. is判断的是a对象是否就是b对象,是通过id来判断的: ==判 ...

  9. c++从txt中读取数据,数据并不是一行路径(实用)

    #include <iostream>#include <fstream>#include <string> using namespace std; //输出空行 ...

  10. Java类名 方法名 常量 变量的命名习惯

    1.包 用于将完成不同功能的类分门别类,放在不同的目录(包)下,包的命名规则:将公司域名反转作为包名,对于包名,每个字母都需要小写. 如果定义类的时候没有使用package(包),那么java就认为我 ...