Target.java
package com.lucas.ModelAdapter; public abstract class Target { public void Request() { System.out.println("Target request!"); } }
Adaptee.java
package com.lucas.ModelAdapter; public class Adaptee { public void specificRequest() { System.out.println("Adaptee request!"); } }
Adapter.java
package com.lucas.ModelAdapter;
public class Adapter extends Target {
private Adaptee adaptee= new Adaptee();
@Override
public void Request() {
adaptee.specificRequest();
}
}
类比STL中stack queue 的实现,是对deque双端队列的适配,stack的pop实际上是对deque一段的pop,stack调用适配器类,适配器再调用deque类。