对象适配器的类图:
package cn.对象适配器模式;
public class Adaptee { //适配者
public void specificRequest() {
System.out.println("适配者");
}
}
package cn.对象适配器模式;
public class Adapter extends Target { //适配器
private Adaptee adaptee;
public Adapter(Adaptee adaptee) {
this.adaptee = adaptee;
}
public void request() {
adaptee.specificRequest();
}
}
package cn.对象适配器模式;
public class Target { //目标类
public void request() {
System.out.println("目标类");
}
}
package cn.对象适配器模式;
public class Client { //客户端
public static void main(String[] args) {
Adaptee adapee = new Adaptee();
Adapter adapter = new Adapter(adapee);
adapter.request();
}
}