OnJava8-Examples/patterns/ProxyDemo.java
Bruce Eckel 49edcc8b17 reorg
2015-06-15 17:47:35 -07:00

49 lines
991 B
Java

//: patterns/ProxyDemo.java
// ©2015 MindView LLC: see Copyright.txt
// Simple demonstration of the Proxy pattern.
interface ProxyBase {
void f();
void g();
void h();
}
class Proxy implements ProxyBase {
private ProxyBase implementation;
public Proxy() {
implementation = new Implementation();
}
// Pass method calls to the implementation:
@Override
public void f() { implementation.f(); }
@Override
public void g() { implementation.g(); }
@Override
public void h() { implementation.h(); }
}
class Implementation implements ProxyBase {
public void f() {
System.out.println("Implementation.f()");
}
public void g() {
System.out.println("Implementation.g()");
}
public void h() {
System.out.println("Implementation.h()");
}
}
public class ProxyDemo {
public static void main(String args[]) {
Proxy p = new Proxy();
p.f();
p.g();
p.h();
}
} /* Output:
Implementation.f()
Implementation.g()
Implementation.h()
*///:~