静态代理模式:
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){
- this.target=target;
- }
- public void print(t){
执行前加代码...
target.print();
执行后加代码;
- }
- }
- 4.stuProxy stuproxy =new stuProxy(stu);
- stuproxy.print();
增强类类类类类的功能
- new stuProxy(new stu()).print();
- new Thread(()->{
- sout("234")
- }).start();
线程代理模式
来源: http://www.bubuko.com/infodetail-3394266.html