1、期待的接口
package com.hhdys.adapter;
/**
* Created by zhangkai on 16/6/4.
*/
public class Target {
public void request(){
System.out.println("普通请求!!!");
}
}
2、现有的接口
package com.hhdys.adapter;
/**
* Created by zhangkai on 16/6/4.
*/
public class Adaptee {
public void specificRequest(){
System.out.println("特殊的请求!!!!");
}
}
3、适配器
package com.hhdys.adapter;
/**
* Created by zhangkai on 16/6/4.
*/
public class Adapter extends Target {
Adaptee adaptee=new Adaptee();
@Override
public void request() {
adaptee.specificRequest();
}
}
4、主程序
package com.hhdys.main;
import com.hhdys.adapter.Adapter;
import com.hhdys.adapter.Target;
/**
* Created by zhangkai on 16/6/4.
*/
public class AdapterMain {
public static void main(String[] args){
Target target=new Adapter();
target.request();
}
}
5、运行结果
特殊的请求!!!!