静态代理模式:
1.真实角色和代理角色实现同一个接口
2.代理角色要代理真实角色
3.代理角色可以做真实角色做不了的事
4.真实角色专注做自己的事
public class StaticProxy { public static void main(String[] args) { // WeddingCompany weddingCompany = new WeddingCompany(new you()); // weddingCompany.happyMarry(); new WeddingCompany(new you()).happyMarry(); // new Thread(new you()).start(). } } interface marry{ void happyMarry(); } //你要结婚了 class you implements marry{ @Override public void happyMarry() { System.out.println("呜呜要结婚了,超级开心!"); } } //婚庆公司代理 class WeddingCompany implements marry{ //真实目标角色 private marry target; public WeddingCompany(marry target) { //真实对象 this.target = target; } @Override public void happyMarry() { before(); this.target.happyMarry(); after(); } private void after() { System.out.println("结婚之后收尾款"); } private void before() { System.out.println("结婚之前布置现场"); } }
标签:Java,target,静态,void,WeddingCompany,happyMarry,new,多线程,public From: https://www.cnblogs.com/zhulei118/p/16772484.html