/**
* 临幸问题(代理设计模式)
* 2017-08-25
* @author Junwei Zhu
*
*/
//整个操作的核心主题
interface Subject
{
public void make();//整个临幸的核心功能
}
class RealSubject implements Subject
{
public void make()
{
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 make()
{
this.prepare();
this.subject.make();
this.destory();
}
public void destory()
{
System.out.println("把娘娘搬走,伺候皇帝睡觉。");
}
}
public class TestProxy
{
public static void main(String[] args)
{
//真实主题完成核心功能,代理主题完成与核心功能有关的其他功能
Subject sub = new ProxySubject(new RealSubject());
sub.make();
}
}