java学习笔记

java类代理模式——java学习之④

2018-02-22  本文已影响0人  pm_kai
package DesignPattern;
interface NetWork{
    public void browse();//只能有抽象方法
}
class Real implements NetWork{
    @Override
    public void browse() {
        System.out.println("浏览页面");
    }
}
class Proxy implements NetWork{
    public NetWork network;
    public Proxy(NetWork network) {
        this.network = network;
    }

    @Override
    public void browse() {
        network.browse();
    }
    
}
public class ProxyPattern {

    public static void main(String[] args) {
        NetWork net = new Proxy(new Real());
        net.browse();
    }

}
上一篇 下一篇

猜你喜欢

热点阅读