代码改变世界

设计模式---代理模式

2011-08-18 17:09  Rollen Holt  阅读(30632)  评论(11编辑  收藏  举报
/**
 * @author Rollen-Holt 设计模式之 代理模式
 */

interface NetWork{
	public abstract void browser();
}

/**
 * Real 类代表用户上网的实际动作,比如查看网页
 * */
class Real implements NetWork{
	public void browser(){
		System.out.println("上网浏览信息");
	}
}

/**
 * 此处使用代理类来完成中间代理的工作,屏蔽实现代理的细节
 * */
class proxy implements NetWork{
	private NetWork netWork;

	proxy(NetWork netWork){
		this.netWork = netWork;
	}

	public void browser(){
		checkName();
		this.netWork.browser();
	}

	private void checkName(){
		// Other codes
	}
}

class hello{
	public static void main(String[] a){
		new proxy(new Real()).browser();
	}
}