package adapter_pattern;
public class Target {//It can be seen as the interface too.
public void request() {
System.out.println("The common request.");
}
}
package adapter_pattern;
public class Adaptee {
public void specificRequest() {// It is different to target's method.
System.out.println("The special request.");
}
}
package adapter_pattern;
public class Adapter extends Target{
private Adaptee adaptee = new Adaptee();
@Override
public void request() {//It is the same comparing with target's interface now.
adaptee.specificRequest();
}
}
package adapter_pattern;
public class Main {
public static void main(String args[]) {
Target target = new Adapter();
target.request();//It actually invokes the adaptee's specialRequest.
}
}
This is a general introduction to the 23 design patterns:
https://blog.csdn.net/GZHarryAnonymous/article/details/81567214