/*接口的定义和使用之:代理设计模式
*简单实现
*/
interface Subject{//整个主题核心功能
public void made();
}
class RealSubject implements Subject{//真实主题类
public void made(){
System.out.println("***真实主题正在进行***");
}
}
class ProxySubject implements Subject{//代理主题类
private Subject subject;
//接收一个真实主题的实例化对象
public ProxySubject(Subject subject){
this.subject = subject;
}
public void prepare(){
System.out.println("***代理主题正在准备***");
}
public void made(){
this.prepare();
this.subject.made();//调用真实主题的made()方法
this.destory();
}
public void destory(){
System.out.println("***代理主题正在收尾***");
}
}
public class TestDemo{
public static void main(String[] args){
Subject sub = new ProxySubject(new RealSubject());
sub.made();
}
}