代理模式
public class ProxyTest {
public static void main(String[] args) {
Server server = new Server();
ProxyServer proxyServer = new ProxyServer(server);
proxyServer.browse();
}
}
interface NetWork{
void browse();
}
//被代理类
class Server implements NetWork{
@Override
public void browse() {
System.out.println("我是真实服务器去访问网络。");
}
}
//代理类
class ProxyServer implements NetWork{
private NetWork netWork;
public ProxyServer(NetWork netWork){
this.netWork = netWork;
}
public void check(){
System.out.println("访问前检查一下网络");
}
@Override
public void browse() {
check();
netWork.browse();
}
}


浙公网安备 33010602011771号