Alex_TD

Java 静态代理模式

静态代理模式

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
1.都需要实现的接口
interface  person{
    void print();
 
}
2.实现接口的类:
public class  stu  implements person{
   @Override
    void print(){
        sout("123");
    }
}
3.代理对象增强实现接口的类:
public class stuProxy implements person{
        private stu  target;
     
    stuProxy(stu target){<br>    this.target=target;<br>  }<br>
        public void print(t){
        执行前加代码。。。
        target.print();
        执行后加代码;
        }
}
4.stuProxy  stuproxy  =new  stuProxy(stu);
   stuproxy.print();
增强类类类类类的功能

 new  stuProxy(new stu()).print();

   new Thread(()->{sout("234")}).start();

线程代理模式

posted on   Alex_TD  阅读(253)  评论(0编辑  收藏  举报

努力加载评论中...
点击右上角即可分享
微信分享提示