package Jiekou;标签:ProxySever,NetWork,void,work,代理,模式,public,brose From: https://www.cnblogs.com/liujy2233/p/16823395.html
/**
* @author liu$
* @version 1.0
* @description: TODO
* @date $ $
*/
//被代理类对象不调方法,把对象放到代理类里面调方法
public class daili {
public static void main(String[] args) {
Server server = new Server();
ProxySever proxySever = new ProxySever(server) ; //相当于把server赋给属性NetWork
proxySever.brose() ;
}
}
interface NetWork{
public void brose();
}
//被代理类
class Server implements NetWork{
@Override
public void brose() {
System.out.println("真实的服务器访问网络");
}
}
//代理类
class ProxySever implements NetWork{
private NetWork work ;
public ProxySever(NetWork work){
this.work = work ;
}
public void check(){
System.out.println("联网前的检查工作");
}
public void brose(){
check();
work.brose();
}
}