Proxy: fronting for another object : Proxy Pattern « Design Pattern « Java Tutorial






interface ProxyBase {
  void taskOne();

  void taskTwo();

  void taskThree();
}
class Implementation implements ProxyBase {
  public void taskOne() {
    System.out.println("Implementation.f()");
  }
  public void taskTwo() {
    System.out.println("Implementation.g()");
  }
  public void taskThree() {
    System.out.println("Implementation.h()");
  }
}
class Proxy implements ProxyBase {
  private ProxyBase implementation;

  public Proxy() {
    implementation = new Implementation();
  }

  public void taskOne() {
    implementation.taskOne();
  }

  public void taskTwo() {
    implementation.taskTwo();
  }

  public void taskThree() {
    implementation.taskThree();
  }
}



public class ProxyDemo {
  public static void main(String args[]) {
    Proxy p = new Proxy();
    p.taskOne();
    p.taskTwo();
    p.taskThree();
  }
}








34.16.Proxy Pattern
34.16.1.Proxy: fronting for another object
34.16.2.The PoolManager using Proxy
34.16.3.Dynamic Proxies