代理模式

来源:互联网 发布:企业避税 知乎 编辑:程序博客网 时间:2024/06/05 13:24
package class1;
interface Network {
public void browse() ;
}
class Real implements Network {
public void browse() {
System.out.println("上网济览信息");
}
}
class Proxy implements Network{
private Network network ;
public Proxy(Network network) {
this.network = network;
}
public void check() {
System.out.println("检查用户是否合法") ;
}
public void browse() {
this.check();
this.network.browse();
}
}
public class ProxyDemo {
public static void main(String args[]) {
Network net = null ;
net = new Proxy(new Real()) ;
net = new Proxy(new Real()) ;
net.browse() ;
}


}
原创粉丝点击