适配器模式(Adapter Pattern)
别名:包装器Wrapper
The Adapter pattern acts as an intermediary between two classes, converting the interface of one class so that it can be used with the other. This enables classes with incompatible interfaces to work together.
1、Target
-定义Client使用的与特定领域相关的接口。
2、Client
-与符合Target接口的对象协同。
3、Adaptee
-定义一个已经存在的接口,这个接口需要适配。
4、Adapter
-对Adaptee的接口与Target接口进行适配。
interface Target { public void request(); }
class Adaptee { public void adaptRequest() { System.out.println("adaptRequest!"); } }
class ClassAdapter extends Adaptee implements Target { public void request() { adaptRequest(); } }
《设计模式:可复用面向对象软件的基础》
原文:https://www.cnblogs.com/diameter/p/13182802.html