结构型模式-代理模式

2020-03-12  本文已影响0人  格林哈

0 结构型模式

1 代理模式

package com.mg.springjiemi.proxy;
public interface ISubject {
    public String request();
}

package com.mg.springjiemi.proxy;
public class SubjectImpl implements ISubject {
    @Override
    public String request() {
        return "跟老板交谈";
    }
}
package com.mg.springjiemi.proxy;
public class SubjectProxy implements ISubject {
    ISubject iSubject;
    public SubjectProxy(ISubject iSubject) {
        this.iSubject = iSubject;
    }
    @Override
    public String request() {
        System.out.println("先跟秘书交谈,安全代理,虚拟代理,远程代理");
        return iSubject.request();
    }
}
package com.mg.springjiemi.proxy;
public class Client {
    public static void main(String[] args) {
        ISubject iSubject = new SubjectImpl();
        SubjectProxy proxy = new SubjectProxy(iSubject);
        String value = proxy.request();
        System.out.println(value);
    }
}


上一篇下一篇

猜你喜欢

热点阅读