P356 接口的应用:代理模式
作者:互联网
接口的应用:代理模式
/*
接口的应用:代理模式
*/
public class NetWorkTest {
public static void main(String[] args) {
Server server = new Server();
new ProxyServer(server);
ProxyServer proxyServer = new ProxyServer(server);
proxyServer.browse();
}
}
interface NetWork{
public void browse();
}
//被代理类
class Server implements NetWork{
@Override
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("联网之前的检查工作");
}
@Override
public void browse() {
check();
work.browse();
}
}
标签:NetWork,P356,browse,void,work,代理,接口,ProxyServer,public 来源: https://blog.csdn.net/weixin_54671087/article/details/120468325