JAVA---接口应用--代理模式

  • 代理设计就是为其他对象提供一种代理以控制对这个对象的访问
package exer;

public class NetWorkTest {
	public static void main(String[] args) {
		Server server=new Server();
		ProxyServer proxyServer=new ProxyServer(server);
		proxyServer.browse();
	}
}
interface NetWork{
	public abstract void browse();
}
//被代理类
class Server implements NetWork{
	public void browse(){
		System.out.println("真实的服务器访问网络");
	}
}
//代理类
class ProxyServer implements NetWork{
	private NetWork work;
	public ProxyServer(NetWork work){
		this.work=work;
	}
	public void check(){
		System.out.println("联网之前的检查工作");
	}
	public void browse(){
		check();
		work.browse();
	}
}

posted @ 2022-02-08 17:53  ice--cream  阅读(44)  评论(0编辑  收藏  举报