interface Subject{ //核心操作主题
public void get();//核心操作
}
class RealSubject implements Subject{
@Override
public void get() {
System.out.println("取回钱款");
}
}
class ProxySubject implements Subject{
private Subject subject; //代理的真实主题
public ProxySubject(Subject subject){
this.subject = subject;
}
public void prepare(){
System.out.println("准备工作");
}
@Override
public void get() {
this.prepare();
this.subject.get(); //真实主题的工作内容
this.destory();
}
public void destory(){
System.out.println("收尾工作");
}
}
public class ProxyDemo {
public static void main(String[] args){
Subject sub = new ProxySubject(new RealSubject());
sub.get();
}
}