感觉和策略模式差不多,
如果说有差别,就是
adapter 模式,大概是对一个已经存在的类进行扩展。?
interface Target{
public void AdapteeMethod();
public void AdapterMethod();
}
class Adaptee{
public void AdapteeMethod(){
System.out.println("Adaptee method");
}
}
class Adapter implements Target{
private Adaptee adaptee;
public Adapter(Adaptee adaptee){
this.adaptee=adaptee;
}
public void AdapteeMethod(){
adaptee.AdapteeMethod();
}
public void AdapterMethod(){
System.out.println("Adapter method");
}
}
public class AdapterTest {
public static void main(String[] args){
Target target = new Adapter(new Adaptee());
target.AdapteeMethod();
target.AdapterMethod();
}
}