Adapter Pattern Demo : Adapter Pattern « Design Pattern « Java Tutorial






class Target {
  public void request() {
  }
}

class Adaptee {
  public void specificRequest() {
    System.out.println("Adaptee: SpecificRequest");
  }
}

class Adapter extends Target {
  private Adaptee adaptee;

  public Adapter(Adaptee a) {
    adaptee = a;
  }

  public void request() {
    adaptee.specificRequest();
  }
}

public class SimpleAdapter {
  public static void main(String args[]) {
    Adaptee a = new Adaptee();
    Target t = new Adapter(a);
    t.request();
  }
}








34.4.Adapter Pattern
34.4.1.Adapter Pattern Demo
34.4.2.Variations on the Adapter pattern.
34.4.3.Adapter pattern: two interfaces