代理模式

2018-08-10  本文已影响0人  javaBoy_hw

1

静态代理

Singer.java

public interface Singer {
    void sing(String song);

    void dance(String dance);
}

SingerImpl.java

public class SingerImpl implements Singer{

    @Override
    public void sing(String song) {

        System.out.println("调试后自己开始唱:" + song);
    }

    @Override
    public void dance(String dance) {

        System.out.println("完备后自己开始跳:" + dance);
    }
}

ProxySinger.java

public class ProxySinger implements Singer {
    Singer mSinger;

    ProxySinger(Singer singer) {
        mSinger = singer;
    }

    @Override
    public void sing(String song) {
        System.out.println("代理帮忙调试麦克风");
        mSinger.sing(song);
    }

    @Override
    public void dance(String dance) {
        System.out.println("代理帮忙准备舞台");
        mSinger.dance(dance);
    }
}

** 总结 **
能代理类

动态代理

cglib

https://blog.csdn.net/pangqiandou/article/details/52964066

https://www.jianshu.com/p/e063ecad9587

https://www.jianshu.com/p/b30ea19c444b

上一篇 下一篇

猜你喜欢

热点阅读