《设计模式》GOF 说明:将一个类的接口转换成客户希望的另外一个接口。Adapter模式使得原本由于接口不兼容而不能一起工作的那些类可以一起工作。
适配器模式 是类对象结构模式。
http://www.bkjia.com/Androidjc/863354.html
http://www.tuicool.com/articles/ymaUnm
http://jcodecraeer.com/a/anzhuokaifa/androidkaifa/2012/1029/485.html //BaseAdapter
http://www.chawenti.com/articles/11684.html //ListAdapter
http://www.cnblogs.com/qianxudetianxia/archive/2012/02/27/2010965.html
//目标角色, 开放给客户的接口 clientInterface
public interface Target {
public void clientInterface();
}
//源角色
public class AdapterSource {
public AdapterSource() { }
public void sourceRole() {
System.out.println("sourceRole() ========");
}
}
//适配器角色,将接口sourceRole()转化为给客户的接口clientInterface
public class Adapter implements Target {
//被代理的设备
private AdapterSource adapterSource;
//装入被代理的设备
public Adapter(AdapterSource adapterSource) {
super();
this.adapterSource = adapterSource;
}
@Override
public void clientInterface() {
adapterSource.sourceRole();
}
}
/**
* Apapter模式使得原本由于接口不兼容而不能再一起工作的那些类可以一起工作
*/
public class Client {
public static void main(String[] args) {
AdapterSource as = new AdapterSource();
Target target = new Adapter(as);
target.clientInterface();
}
}