在阎宏博士的《JAVA与模式》一书中开头是这样描述适配器(Adapter)模式的:
适配器模式把一个类的接口变换成客户端所期待的另一种接口,从而使原本因接口不匹配而无法在一起工作的两个类能够在一起工作。
适配器模式的用途
用电器做例子,笔记本电脑的插头一般都是三相的,即除了阳极、阴极外,还有一个地极。而有些地方的电源插座却只有两极,没有地极。电源插座与笔记本电脑的电源插头不匹配使得笔记本电脑无法使用。这时候一个三相到两相的转换器(适配器)就能解决此问题,而这正像是本模式所做的事情。
适配器模式的结构
适配器模式有类的适配器模式和对象的适配器模式两种不同的形式。
类适配器模式
类的适配器模式把适配的类的API转换成为目标类的API。
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAmwAAAEhCAIAAABN2WtdAAAgAElEQVR4nO3dLYzcSBqHcR/LgZMWRodCLAUOXGDpAg/GbGEkk2W30lm6kRYMshYOsRQpJMAgYSujQMMQS4GR0TAHLmgQ6AOvpvymyva4e+y2q+f5gajT47bd1eX621X+CDoAAHCSYOsVAADAV4QoAAAnIkQBADgRIQoAwIkIUQAATkSIAgBwIkIUAIATEaIAAJyIEAUA4ESEKAAAJyJEAQA4ESEKAMCJCFEAAE5EiAIAcCJCFACAEz0cond3dxXgm7u7u/U3HwBP3QMh+vXr1wDw06dPn86zFQF4sh4I0aqqgiB4/fr1DeCPN2/eBEHw/v37s2xEAJ6uWSFKYwS/UG8BnAchigtEvQVwHoQoLhD1FsB5EKJd13Vt2269CufzFL7sE6m3ADb3hEI0SZLB94uiKIpCvxPHcRRFZ1mpYVmWyVqlabr4zN3va4wVkXcuqd4C2LOnEqLzE1TePDa9yrI8cc0ceZ6bVQrDsK7rpeZsXHyOXky9BbBzTyJEj0rQZRdxgiiKTHAeDoelZmu57By9jHq7N9x3BZ5a9dYrlx+ipyVo0zTWOxNDiUVRHNv9687f0CG6qgvO0Quot3vDfVfgtfVuvXLhIXpsglZVlWVZHMdZlpk3D4dDmqZRFKX34jg2f8qyLE3TMAyzLMuyrKoq88G6rtM0raoqz3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7ueZayQ7JLvZP7d67tCYUosBTq7eLOH6Kys7t2iJ5hKdgWIQocjXq7OIoUniJEgaNRbxdHkcJTuwjR6+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+mp3n79i0jIoDXHjm4I91a7EzvEyG6pSAIuFMucPEeObgjR7HuIxSxB4TolghR4OIt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kNmqCNBr7C+xCWOY5M9EmayGtJ/rll5KayD0WMvbhGyzkd9RAbF3fez+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+Op1XuC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bB+9uzvnewne7Smjc1Fs43gXYCZLu5lzlLfyljbjPVeCK4F2AnSDpbg5RCkcE7wLsBEl3c4hSOCJH9e7d3V0DcCju7++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/yKoYN3A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G08/irdImvev0mpZTqe/tCX0j+oKxAbY9tua82zSNPe3k9CCTip2U8TIyJmrVRFdVVcVx7IzHtb0BJsdZ+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接口的实现,一个系统如果太多出现这种情况,无异于一场灾难。因此如果不是很有必要,可以不使用适配器,而是直接对系统进行重构。
缺省适配模式
缺省适配(Default Adapter)模式为一个接口提供缺省实现,这样子类型可以从这个缺省实现进行扩展,而不必从原有接口进行扩展。作为适配器模式的一个特例,缺省是适配模式在JAVA语言中有着特殊的应用。
鲁智深的故事
和尚要做什么呢?吃斋、念经、打坐、撞钟、习武等。如果设计一个和尚接口,给出所有的和尚都需要实现的方法,那么这个接口应当如下:
public interface 和尚 {
public void 吃斋();
public void 念经();
public void 打坐();
public void 撞钟();
public void 习武();
public String getName();
}
显然,所有的和尚类都应当实现接口所定义的全部方法,不然就根本通不过JAVA语言编辑器。像下面的鲁智深类就不行。
public class 鲁智深 implements 和尚{
public void 习武(){
拳打镇关西;
大闹五台山;
大闹桃花村;
火烧瓦官寺;
倒拔垂杨柳;
}
public String getName(){
return "鲁智深";
}
}
由于鲁智深只实现了getName()和习武()方法,而没有实现任何其他的方法。因此,它根本就通不过Java语言编译器。鲁智深类只有实现和尚接口的所有的方法才可以通过Java语言编译器,但是这样一来鲁智深就不再是鲁智深了。以史为鉴,可以知天下。研究一下几百年前鲁智深是怎么剃度成和尚的,会对Java编程有很大的启发。不错,当初鲁达剃度,众僧说:“此人形容丑恶、相貌凶顽,不可剃度他",但是长老却说:”此人上应天星、心地刚直。虽然时下凶顽,命中驳杂,久后却得清净。证果非凡,汝等皆不及他。”
原来如此!看来只要这里也应上一个天星的话,问题就解决了!使用面向对象的语言来说,“应”者,实现也;“天星”者,抽象类也。
public abstract class 天星 implements 和尚 {
public void 吃斋(){}
public void 念经(){}
public void 打坐(){}
public void 撞钟(){}
public void 习武(){}
public String getName(){
return null;
}
}
鲁智深类继承抽象类“天星”
public class 鲁智深 extends 和尚{
public void 习武(){
拳打镇关西;
大闹五台山;
大闹桃花村;
火烧瓦官寺;
倒拔垂杨柳;
}
public String getName(){
return "鲁智深";
}
}
这个抽象的天星类便是一个适配器类,鲁智深实际上借助于适配器模式达到了剃度的目的。此适配器类实现了和尚接口所要求的所有方法。但是与通常的适配器模式不同的是,此适配器类给出的所有的方法的实现都是“平庸”的。这种“平庸化”的适配器模式称作缺省适配模式。
在很多情况下,必须让一个具体类实现某一个接口,但是这个类又用不到接口所规定的所有的方法。通常的处理方法是,这个具体类要实现所有的方法,那些有用的方法要有实现,那些没有用的方法也要有空的、平庸的实现。
这些空的方法是一种浪费,有时也是一种混乱。除非看过这些空方法的代码,程序员可能会以为这些方法不是空的。即便他知道其中有一些方法是空的,也不一定知道哪些方法是空的,哪些方法不是空的,除非看过这些方法的源代码或是文档。
缺省适配模式可以很好的处理这一情况。可以设计一个抽象的适配器类实现接口,此抽象类要给接口所要求的每一种方法都提供一个空的方法。就像帮助了鲁智深的“上应天星”一样,此抽象类可以使它的具体子类免于*实现空的方法。
缺省适配模式的结构
缺省适配模式是一种“平庸”化的适配器模式。
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAWUAAAFiCAIAAACh4l5UAAAgAElEQVR4nO2dL4zkRtrGfWyPHYwOhVgKXHjA0hd4MM0CVzI5diedwUgHFlmBSyytFLLAIGGR0ULDEEuBK6NlXhhgsLA+8Gjeeeetck11T3e7Zub5oW7b7frT9T71/63CEUJIGsXeESCEPBmoF4SQVKgXhJBUqBeEkFSoF4SQVKgXhJBUqBeEkFSoF4SQVKgXhJBUqBeEkFSoF4SQVKgXhJBUqBeEkFSoF4SQVKgXhJBUqBeEkFSoF4SQVDLSi8+fP4+EvGw+f/68tyHGyEUvPn36VBBCiuLjx497m+MmuejFOI5FUfzwww9vCXmpvHnzpiiKDx8+7G2Om+SlFznnFCGXJn8roF4Qkgv5WwH1gpBcyN8KqBe7Mc/zuq7BW8Mw+A9fPkb7ME3T1i0/H543+VsB9WIfpmlqmiZ4q2kaY0Jt2xZFsaNkNE2D2b6qqi7x/rqug9f7vu/7/hIh5kn+VkC92IGjxAJ0XXdUEGc0M4gFPldVdSHZomS4p2AF1Itrc4JYnMCW+Z1AVVXnilUcSkb+VkC9uConiMU0TdM0tW1rLsKE5nmepmlZFn2r67qyLPFDvzmA6/IVb+i6DoMp+KpvVVXV9735lXNuWRb9cOKtYJSEFy4Z+VsB9eJ6nNaygDSYgYNpmsqybJoGllxVlUgGDDuoF4jAsizLshwOB/wEhl2W5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MktZbHv78MIKY8o/nbwXUi33ASoq9Y3Ft+r5f13Vd1+svcr0+/oHVDw555m8F1IsdkDOlX4LZvGSWZcGxDOM4pozs5m8F1AtCciF/K6BeEJIL+VsB9YKQXMjfCvLSi5ubm5GQl8q7d++oF0n8/vvvBSGkKH755Ze9zXGTXPTCOff+/fu3hLxs3r179/Xr171tcZOM9IIQkjnUC0JIKtQLQkgq1AtCSCrUC0JIKtQLQkgq1AtCSCrUC0JIKtQLQkgq1AtCSCrUC0JIKtQLQkgq1AtCSCrUC0JIKtQLQkgq1AtCSCrUC0JIKtQLQkgq1AtCSCrUC0JIKtQLQkgq1AtCSCr/D+kCPGGVhUtNAAAAAElFTkSuQmCC" alt="" />
public interface AbstractService {
public void serviceOperation1();
public int serviceOperation2();
public String serviceOperation3();
}
public class ServiceAdapter implements AbstractService{ @Override
public void serviceOperation1() {
} @Override
public int serviceOperation2() {
return 0;
} @Override
public String serviceOperation3() {
return null;
} }
可以看到,接口AbstractService要求定义三个方法,分别是serviceOperation1()、serviceOperation2()、serviceOperation3();而抽象适配器类ServiceAdapter则为这三种方法都提供了平庸的实现。因此,任何继承自抽象类ServiceAdapter的具体类都可以选择它所需要的方法实现,而不必理会其他的不需要的方法。
适配器模式的用意是要改变源的接口,以便于目标接口相容。缺省适配的用意稍有不同,它是为了方便建立一个不平庸的适配器类而提供的一种平庸实现。
在任何时候,如果不准备实现一个接口的所有方法时,就可以使用“缺省适配模式”制造一个抽象类,给出所有方法的平庸的具体实现。这样,从这个抽象类再继承下去的子类就不必实现所有的方法了。