public interface People {
public void work();
}
public class RealPeople implements People {
public void work() {
System.out.println("工作中...");
}
}
/**
* 代理类
*
*/
public class Proxy implements People {
private RealPeople realPeople;
public Proxy(RealPeople realPeople) {
this.realPeople = realPeople;
}
public void work() {
System.out.println("before work...");
realPeople.work();
System.out.println("after work...");
}
}
public class ProxyTest {
public static void main(String[] args) {
Proxy proxy = new Proxy(new RealPeople());
proxy.work();
}
}