package DemoThread; //静态代理总结 /** * 1.真实对象和代理对象都要实现统一接口 * 2.代理对象需要代理真实角色 *好处: * 1.代理对象可以做很多真实对象做不了的事情 * 2.真实对象专注做自己的事情 * */ public class StaticProxy { public static void main(String[] args) { // WenddingCompany wenddingCompany=new WenddingCompany(new You()); // wenddingCompany.HappyMarry(); new WenddingCompany(new You()).HappyMarry(); } } interface Marry{ void HappyMarry(); } //真实角色 class You implements Marry{ @Override public void HappyMarry() { System.out.println("小哟结婚了,开心"); } } //代理角色 class WenddingCompany implements Marry{ private Marry target; public WenddingCompany(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("结婚之前布置现场"); } }