适配器模式是android开发中最常用的模式之一,我们在开发显示列表时经常会用到
适配器模式(Adapter Pattern)
Convert the interface of a class into another interface clientsexpect. Adapter lets classes work together that couldn't other-wise because of incompatible interfaces.
将一个类的接口变换成客户端所期待的另一种接口,从而使原本因接口不匹配而无法在一起工作的两个类能够在一起工作。
主要类
public class Adaptee {
public void doSomething(){
System.out.println("Adaptee");
}
}
public class Adapter extends Adaptee implements Target {
public void request() {
super.doSomething();
}
}
public class ConcreteTarget implements Target {
public void request() {
System.out.println("ConcreteTarget");
}
}
public interface Target {
public void request();
}
运行结果
ConcreteTarget
Adaptee