美文网首页
代理模式

代理模式

作者: javaBoy_hw | 来源:发表于2018-08-10 14:33 被阅读0次

    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

    相关文章

      网友评论

          本文标题:代理模式

          本文链接:https://www.haomeiwen.com/subject/plgkbftx.html