package Adapter;
public interface Target {
void req();
}
package Adapter;
/***
* 被适配的对象。。相当于键盘
* @author zw
*
*/
public class Adaptee {
public void request() {
System.out.println("可以完成客户请求的需要功能");
}
}
package Adapter;
/***
* 适配器本身
* 相当于usb和ps/2的转接器
* @author zw
*
*/
public class Adpater2 implements Target {
private Adaptee a;
public Adpater2(Adaptee a) {
super();
this.a = a;
}
@Override
public void req() {
a.request();
}
}
package Adapter;
/***
* 相当于笔记本 (只有usb接口)
* @author zw
*
*/
public class Client2 {
public void test1(Target t) {
t.req();
}
public static void main(String[] args) {
Client2 c = new Client2();
Adaptee a = new Adaptee();
Target t =new Adpater2(a);
c.test1(t);
}
}