适配器模式把一个类的接口变换成客户端所期待的另一种接口,从而使原本因接口不匹配而无法在一起工作的两个类能够在一起工作。


适配器模式的用途

  用电器做例子,笔记本电脑的插头一般都是三相的,即除了阳极、阴极外,还有一个地极。而有些地方的电源插座却只有两极,没有地极。电源插座与笔记本电脑的电源插头不匹配使得笔记本电脑无法使用。这时候一个三相到两相的转换器(适配器)就能解决此问题,而这正像是本模式所做的事情。

适配器模式的结构

  适配器模式有类的适配器模式对象的适配器模式两种不同的形式。

类适配器模式

  类的适配器模式把适配的类的API转换成为目标类的API。

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAmwAAAEhCAIAAABN2WtdAAAgAElEQVR4nO3dLYzcSBqHcR/LgZMWRodCLAUOXGDpAg/GbGEkk2W30lm6kRYMshYOsRQpJMAgYSujQMMQS4GR0TAHLmgQ6AOvpvymyva4e+y2q+f5gajT47bd1eX621X+CDoAAHCSYOsVAADAV4QoAAAnIkQBADgRIQoAwIkIUQAATkSIAgBwIkIUAIATEaIAAJyIEAUA4ESEKAAAJyJEAQA4ESEKAMCJCFEAAE5EiAIAcCJCFACAEz0cond3dxXgm7u7u/U3HwBP3QMh+vXr1wDw06dPn86zFQF4sh4I0aqqgiB4/fr1DeCPN2/eBEHw/v37s2xEAJ6uWSFKYwS/UG8BnAchigtEvQVwHoQoLhD1FsB5EKJd13Vt2269CufzFL7sE6m3ADb3hEI0SZLB94uiKIpCvxPHcRRFZ1mpYVmWyVqlabr4zN3va4wVkXcuqd4C2LOnEqLzE1TePDa9yrI8cc0ceZ6bVQrDsK7rpeZsXHyOXky9BbBzTyJEj0rQZRdxgiiKTHAeDoelZmu57By9jHq7N9x3BZ5a9dYrlx+ipyVo0zTWOxNDiUVRHNv9687f0CG6qgvO0Quot3vDfVfgtfVuvXLhIXpsglZVlWVZHMdZlpk3D4dDmqZRFKX34jg2f8qyLE3TMAyzLMuyrKoq88G6rtM0raoqz3Mzw6IosiyTflr5SBRF0hts/pSmqfxJr3Ce53Vdl2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5hKdgWIQocjXq7OIoUniJEgaNRbxdHkcJTuwjR6+vrCvDH7e0tLf6yKkIUflq76j4Qop8/fw6wmr/97W9br8Il+/Dhw0qbzRNEiMJTG4do13Vv3769wdJ+//33f/7zn0EQ/P3vf//vf/+79epcoNvb2+/fv6+02TxBhCg8tX2IYg03NzdBEFxfXz979uyXX37ZenWAB1SM7MBPaw/uEKIb+Pr167Nnz/797393XXd9fR0EwZ9//rn1SgFTGNlZG4M7q1pvcIcQ3cCrV6+ePXt2d3fXdd33799fvHjx/Plz+h6xc4zsrMQM7vzjH//43//+t/XqXKBVB3cI0XN7//59EAS3t7fmnaqqgiD47bffNlwrAFu5ubkJguDNmze0Az4iRM/q27dvz58/v7q6st6X7efLly+brBWArejBndevXz979uzr169brxSOQIie1S+//DIYliZc6dQFnhQ9uPPly5dnz569fv1665XCEQjR8/n06dNEd4108/7xxx9nXisAW3EHd3777beAMw29QoieiZxA9OLFi4ljTb1PCuCyDQ7u/PXXX8+fP3/58iWdUr4gRM9ELmX59OnTxDR3d3dmdATAZRsb3Hn79q11eIo9I0TPQYY65txU4Y8//lj1kiYAezA9uHN1dfXTTz99+/btzGuFExCi5zB/k/j+/fvV1dXz58/ZfoBL9eDgjlz29uuvv555xXACQnR1ctOpt2/fzpxebg3z5s2bVdcKwFbmDO68fv2ay968QIiu69u3b8+ePXv16tVRn/r111+DIKiqap2VArCZmYM70nT8/PPP51krnIwQXddpV09///6dM/SAizR/cEfuZMTlLjtHiK7ow4cPQRDc3Nyc8Nk///zz5M8C2KejBndkZ5oba+8cIbqWx1/vJUexDIoAl+GEwZ3H7IjjPAjRtci45s3NzcmPwZPth0ER4DKcNrjz888/P3v2jNP1d4sQXcW3b98WfBLe58+ft/5CAB7l5GPKL1++BEHADXV3ixBdy/v37x98yl0QBP/5z3+mp3n79i0jIoDXHjm4I91a7EzvEyG6pSAIuFMucPEeObgjR7HuIxSxB4TolghR4OItOLjDwegOEaJbIkSBp2Dm4A4jOz4iRLdEiAIQQUB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Gyzkd9RAbF3fez+4uCBi9xcYtFKo8U/pyOaEIUGyJE0Tt/YzTzSkQvlrIf+swj9y6Al4cQxYYIUfTO3BiVZTnnKkAvlrI35rh28Cb1F4YQxYYIUfTO3BiZsb0LWAo2RIhiQ4QoejRG8BH1FhsiRNGjMYKPqLfYECGKHo0RfES9xYYIUfRojOAj6i02RIiiR2MEH1FvsSFCFD1pjK6vryvAH7e3t4QotkKIovf58+cA8NOHDx+23oDwFBGi+MHbt29vAN/c3t5+//59660HTxEhCgDAiQhRAABORIgCAHAiQhQAgBMRogAAnIgQBQDgRIQoAAAnIkQBADgRIQoAwIkIUQAATkSIAgBwIkIUAIATEaIAAJyIEAUA4ESEKAAAJyJEAQA4ESEKAMCJCFEAAE70f8FVSf4SOWD6AAAAAElFTkSuQmCC" alt="" />

  在上图中可以看出,Adaptee类并没有sampleOperation2()方法,而客户端则期待这个方法。为使客户端能够使用Adaptee类,提供一个中间环节,即类Adapter,把Adaptee的API与Target类的API衔接起来。Adapter与Adaptee是继承关系,这决定了这个适配器模式是类的:

  模式所涉及的角色有:

  ●  目标(Target)角色:这就是所期待得到的接口。注意:由于这里讨论的是类适配器模式,因此目标不可以是类。

  ●  源(Adapee)角色:现在需要适配的接口。

  ●  适配器(Adaper)角色:适配器类是本模式的核心。适配器把源接口转换成目标接口。显然,这一角色不可以是接口,而必须是具体类。

源代码

public interface Target {
/**
* 这是源类Adaptee也有的方法
*/
public void sampleOperation1();
/**
* 这是源类Adapteee没有的方法
*/
public void sampleOperation2();
}

  上面给出的是目标角色的源代码,这个角色是以一个JAVA接口的形式实现的。可以看出,这个接口声明了两个方法:sampleOperation1()和sampleOperation2()。而源角色Adaptee是一个具体类,它有一个sampleOperation1()方法,但是没有sampleOperation2()方法。

public class Adaptee {

    public void sampleOperation1(){}

}

  适配器角色Adapter扩展了Adaptee,同时又实现了目标(Target)接口。由于Adaptee没有提供sampleOperation2()方法,而目标接口又要求这个方法,因此适配器角色Adapter实现了这个方法。

public class Adapter extends Adaptee implements Target {
/**
* 由于源类Adaptee没有方法sampleOperation2()
* 因此适配器补充上这个方法
*/
@Override
public void sampleOperation2() {
//写相关的代码
} }

对象适配器模式

  与类的适配器模式一样,对象的适配器模式把被适配的类的API转换成为目标类的API,与类的适配器模式不同的是,对象的适配器模式不是使用继承关系连接到Adaptee类,而是使用委派关系连接到Adaptee类。

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAn0AAAFJCAIAAABhEgy8AAAgAElEQVR4nO2dLYzdSLqwfVmWLZxlIZYCAxdY2sCFMVsYyeSyu9K1tC0tCLIWNrE00pAAgxm2MlpoGGJp4MgozIEDDAJ9wfv1+72pst3H3W6fss/zgNZpH/+U65Trcf1HIwAAAOxFdO0AAAAA3BB4FwAAYD/wLgAAwH7gXQAAgP3AuwAAAPuBdwEAAPYD7wIAAOwH3gUAANgPvAsAALAfeBcAAGA/8C4AAMB+4F0AAID9wLsAAAD7gXcBAAD2A+8CAADsB94FAADYD7wLAACwH3gXAABgP/AuAADAfuBdAACA/cC7AAAA+4F3AQAA9gPvAgAA7AfeBQAA2A+8CwAAsB94FwAAYD/wLgAAwH7gXQAAgP3AuwAAAPuBdwEAAPYD7wIAAOwH3gUAANgPvAsAALAfeBcAAGA/tvHuly9fGoAD8uXLl00eAQCAC9nAu7/99lsEcFj+85//PP8pAAC4kA282zRNFEXv37//CHAoPnz4EEXRp0+fnv8UAABcyGbeJfOCw0HSBYD9wbtwu5B0AWB/8C7cLiRdANgfvOsyDMPk9r7vdw5JmJwpHk6WdAHgEODd78jzvOs6f3vbtnme2y1d18VxXNf1XkFz6bquKIq6rrMsa9t28/NnWTa5vaqqqqo2v9xVOFPSBYCjgHf/P3meTwrMl66QpumkpOcYhmGuMP0EkiSRD0VRpGm61Wktp1fvaZIuABwIvPv/WCvdJ9A0zVYF07Zt1bsvyrnVe46kGxrMogNHZM8pdPDuOD5VuqskOgxDkiRrvTtXnt7Nu+Op1XuCpBsazKIDx2W3KXTw7lOkWxRFURR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Lu5lzlLfyljbjPVeCK4F2AnSDpbg5RCkcE7wLsBEl3c4hSOCJH9e7d3V0DcCju7++RxLY0eBcOyM7pdgPvfv78OYIX47/+67+uHYST8/PPPz//KQAB78IROZ53x3H88ccfP8LW/POf//zTn/4URdEf/vCH//3f/712cM7J/f39t2/fNnkKYMS7cEwO6V14CaQW9MOHD69evfrb3/527eAAPE5DqxMckJ2bnPBuoHz9+vWHH354+/btOI53d3dRFP373/++dqAAHoFWJzguuzU54d1A+fvf/x5FUdM04zh++/bt9evXP/zwAzWiED60Or0E//jHP16/fh1F0evXr//xj39cOzgnZM8mJ7wbIr/++msURe/fv9ctTdNEUfT3v//9iqECgKvw+++/v3v3TrKFX3/99d27d7///vu1AwVPB++GyLt37169evXlyxe78cOHD/LUXSlQAHAFVLrjOEZRNI4j6j06eDc4/v3vf0dRdHd352zXFl9qmwFuBCvd8cG7I+o9OHg3LJabcj99+hRF0b/+9a/9AwYAO+NIdzTeHVHvkcG7YfGvf/1ruVvdZBU0AJwMX7rj994dUe9hwbsB8fXr11evXsnYoTm+fPny6tWrv/71r7uFCgB2ZlK6o+fdEfUeE7wbEH/7298u6Tn1aJkYAI7LnHTHKe+OqPeA4N1QkEECHz58eHTPb9++vX379ocffvj69esOAQOAPXn//v3cy/ekd8dx/PXXX+2wQwgcvBsKb9++ffXq1YUqlVmBLpE0AJyGOe/CseBXDALpqHx/f3/5If/93/+tE1oBwC2Ad88Bv+L1+fbt2w8//PD69etVA3PlqDdv3jCcF+BGwLvngF/x+shUzE9Y9kBm2Pj48eMLBAoAggPvngN+xSvzzHFB79+/f/XqFZNHAtwCePcc8Ctemffv30vL7tOWjfz555+jKPrzn/987fsAgBcH754DfsVr8vXr161Wjvz8+fO17wYAXha8ew74Fa/Mp0+flleFjKLof/7nf5b3+fHHH+ldBXB68O454FcMnSiKmI0ZAEa8exb4FUMH7wKAgHfPAb9i6OBdABDw7jngVwwdvAsAAt49B/yKoYN3AUDAu+eAXzF08C4ACHj3HPArhs67d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AbY9tua82zSNPe3k9CCTip2U8TIyJmrVRFdVVcVx7IzHtb0BJsdZ+QVx21Q8OVbKB+9CIOBdWMeFmVeSJDI0SJpXbW8a2S7dVmU36XYr3YmdD+PDzA8yHskpsEobquwp59GvZP5IO3ZF0F5gTr/ZJEnk5E3TSD8s/UrqjYsHHr20WF8agyXw2lNakDZjGQBjAyyNwY5QNcByNv0V0jRVXYnMtFt1/D2TpVj7o4wPY3IWf9IJZAD02tk2Jh0pU3k4k36M89HSdZ3+KNKc8aj+8S4EAt6FdeyfeTkZ7gvx0l15A0R9PAzDDjXMVwfvQiDgXVjH/pnXcgvrVtygd8eH2u8wl4jYHLwLgYB3YR07Z146J9GLrpajY378hmo4DXgXAgHvwjrIvOCgkHQhEPAurIPMCw4KSRcCAe/COsi84KCQdCEQ8C6sQzKvu7u7BuBQ3N/f410IAbwL6/j8+XMEcFh+/vnnaz9DcOvgXVjNjz/++BHggNzf33/79u3aDxDcOngXAABgP/AuAADAfuBdAACA/cC7AAAA+4F3AQAA9gPvAgAA7AfeBQAA2A+8CwAAsB94FwAAYD/wLgAAwH7gXQAAgP3AuwAAAPuBdwEAAPYD7wIAAOwH3gUAANgPvAsAALAfeBcAAGA/8C4AAMB+4F0AAID9wLsAAAD78X9e9TrQ/FfumAAAAABJRU5ErkJggg==" alt="" />

  从上图可以看出,Adaptee类并没有sampleOperation2()方法,而客户端则期待这个方法。为使客户端能够使用Adaptee类,需要提供一个包装(Wrapper)类Adapter。这个包装类包装了一个Adaptee的实例,从而此包装类能够把Adaptee的API与Target类的API衔接起来。Adapter与Adaptee是委派关系,这决定了适配器模式是对象的。

源代码

public interface Target {
/**
* 这是源类Adaptee也有的方法
*/
public void sampleOperation1();
/**
* 这是源类Adapteee没有的方法
*/
public void sampleOperation2();
}
public class Adaptee {

    public void sampleOperation1(){}

}
public class Adapter {
private Adaptee adaptee; public Adapter(Adaptee adaptee){
this.adaptee = adaptee;
}
/**
* 源类Adaptee有方法sampleOperation1
* 因此适配器类直接委派即可
*/
public void sampleOperation1(){
this.adaptee.sampleOperation1();
}
/**
* 源类Adaptee没有方法sampleOperation2
* 因此由适配器类需要补充此方法
*/
public void sampleOperation2(){
//写相关的代码
}
}

类适配器和对象适配器的权衡

  ●  类适配器使用对象继承的方式,是静态的定义方式;而对象适配器使用对象组合的方式,是动态组合的方式。

  ●  对于类适配器,由于适配器直接继承了Adaptee,使得适配器不能和Adaptee的子类一起工作,因为继承是静态的关系,当适配器继承了Adaptee后,就不可能再去处理  Adaptee的子类了。

     对于对象适配器,一个适配器可以把多种不同的源适配到同一个目标。换言之,同一个适配器可以把源类和它的子类都适配到目标接口。因为对象适配器采用的是对象组合的关系,只要对象类型正确,是不是子类都无所谓。

  ●   对于类适配器,适配器可以重定义Adaptee的部分行为,相当于子类覆盖父类的部分实现方法。

     对于对象适配器,要重定义Adaptee的行为比较困难,这种情况下,需要定义Adaptee的子类来实现重定义,然后让适配器组合子类。虽然重定义Adaptee的行为比较困难,但是想要增加一些新的行为则方便的很,而且新增加的行为可同时适用于所有的源。

  ●  对于类适配器,仅仅引入了一个对象,并不需要额外的引用来间接得到Adaptee。

     对于对象适配器,需要额外的引用来间接得到Adaptee。

  建议尽量使用对象适配器的实现方式,多用合成/聚合、少用继承。当然,具体问题具体分析,根据需要来选用实现方式,最适合的才是最好的。

适配器模式的优点

  •   更好的复用性

  系统需要使用现有的类,而此类的接口不符合系统的需要。那么通过适配器模式就可以让这些功能得到更好的复用。

  •   更好的扩展性

  在实现适配器功能的时候,可以调用自己开发的功能,从而自然地扩展系统的功能。

适配器模式的缺点

  过多的使用适配器,会让系统非常零乱,不易整体进行把握。比如,明明看到调用的是A接口,其实内部被适配成了B接口的实现,一个系统如果太多出现这种情况,无异于一场灾难。因此如果不是很有必要,可以不使用适配器,而是直接对系统进行重构。

java设计模式之——适配器模式的更多相关文章

  1. java设计模式5——适配器模式

    java设计模式5--适配器模式 1.结构型模式介绍 1.1.作用 从程序的结构上实现松耦合,从而可以扩大整体的类结构,用来解决更大的问题. 分类: 适配器模式 代理模式 桥接模式 装饰模式 组合模式 ...

  2. Java设计模式之适配器模式(项目升级案例)

    今天是我学习Java设计模式中的第三个设计模式了,但是天气又开始变得狂热起来,对于我这个凉爽惯了的青藏人来说,又是非常闹心的一件事儿,好了不管怎么样,目标还是目标(争取把23种Java设计模式接触一遍 ...

  3. Java设计模式----初识适配器模式

    [声明] 欢迎转载,但请保留文章原始出处→_→ 生命壹号:http://www.cnblogs.com/smyhvae/ 文章来源:http://www.cnblogs.com/smyhvae/p/3 ...

  4. Java设计模式应用——适配器模式

    性能监控系统中,存在告警模块和报表模块,告警结果和报表结果都需要导出. 由于告警开发进度较快,已经实现了excel导出.csv导出.zip导出功能,现在报表需要excel导出.csv导出.pdf导出功 ...

  5. Java设计模式之适配器模式(Adapter)

    转载:<JAVA与模式>之适配器模式 这个总结的挺好的,为了加深印象,我自己再尝试总结一下 1.定义: 适配器模式把一个类的接口变换成客户端所期待的另一种接口,从而使原本因接口不匹配而无法 ...

  6. Java设计模式中适配器模式的实现方法

    在Java开发中,我们常常需要用到Java接口型模式中的适配器模式,那适配器设计模式到底是什么模式呢? 适配器模式(Adapter)就是把一个类的接口变换成客户端所期待的另一种接口,从而使原本接口不匹 ...

  7. 夜话JAVA设计模式之适配器模式(adapter pattern)

    适配器模式:将一个类的接口,转换成客户期望的另一个接口,让不兼容的接口变成兼容. 1.类适配器模式:通过多重继承来实现适配器功能.多重继承就是先继承要转换的实现类,再实现被转换的接口. 2.对象适配器 ...

  8. java设计模式之适配器模式

    说到适配器,我们可能会想到电脑的适配器,没错,其实作用是一样的,电脑的适配器在中国可以使用,在美国也可以使用,它的主要作用是在新接口和老接口之间进行适配..这就是一个适配的过程,适配器模式的类图如下: ...

  9. java设计模式之六适配器模式(Adapter)

    适配器模式将某个类的接口转换成客户端期望的另一个接口表示,目的是消除由于接口不匹配所造成的类的兼容性问题.主要分为三类:类的适配器模式.对象的适配器模式.接口的适配器模式.首先,我们来看看类的适配器模 ...

随机推荐

  1. 数据库基础(子查询练习、链接查询(join on 、union)及其练习)

    子查询练习一:查询销售部里的年龄大于35岁的人的所有信息 练习二:将haha表中部门的所有数字代码转换为bumen表中的字符串显示 练习三:将haha表中部门的所有数字代码转换为bumen表中的字符串 ...

  2. springdata+redis配置详解

    springdata设计初衷是位简化数据类型和数据的持久化存储,它并不局限是关系型数据库还是nosql数据库,都提供了简化的数据库连接,让数据获取变得更加的简单.所有这些的实现有统一的api提供. 本 ...

  3. matlab之kmeans聚类用法

    kmeans函数用法如下: [IDX,C,sumd,D] = kmeans(X,2,'Distance','city','Replicates',5,'Options',opts); 参数含义如下:I ...

  4. Visual Studio调试技巧 -- Attach to Process #Reprinted#

    from:http://www.cnblogs.com/lyosaki88/p/3481338.html 一般写完代码时,我们通常会启动调试运行一下看看是否正确,启动运行的方式无非是F5-- Star ...

  5. perl 处理json 数组格式

    [root@dr-mysql01 ~]# cat a1.pl use Encode; use JSON; use URI::Escape; use LWP::Simple; my $host = &q ...

  6. UITableView 协议中常用的方法

    UITableViewDataSource 协议中常用方法 1.设置右边 索引值 - ( NSArray *)sectionIndexTitlesForTableView:( UITableView ...

  7. 中国A股市场缘何遭遇9连跌?

    端午长假刚过,当投资者对“红六月”预期信心满满的时候,A股市场却遭遇了诡异的跌势,截止6月17日收盘,A股出现了罕见的“9连跌”.不仅上证综指失守2200点年线整数位,深证成指跌幅则高达3%以上,而且 ...

  8. ceph install

    Ceph : performance, reliability and scalability storage solution Contents 1 Introduction 1.1 Testing ...

  9. C#中的DataTable简单使用Merge

    //不同结构的DataTable追加第二个DataTable数据在对应行后的 简单使用//不同结构的DataTable追加在行后面的合并 DataTable dt = new DataTable(); ...

  10. STM32使用串口1配合DMA接收不定长数据,减轻CPU载荷

    STM32使用串口1配合DMA接收不定长数据,减轻CPU载荷 http://www.openedv.com/thread-63849-1-1.html 实现思路:采 用STM32F103的串口1,并配 ...