实现接口类方法HappyMarry
我结婚专注自己的事(结婚)
婚庆公司做布置
最后主线程调用
整体代码
public class StaticProxy { public static void main(String[] args) { WeddingCompany cost = new WeddingCompany(new Myself()); cost.HappyMarry();//以上两行可写成new WeddingCompany(new Myself())。HappyMarry } } interface Marry { void HappyMarry(); } //真实角色,我去结婚 class Myself 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 before() { System.out.println("结婚之前布置现场"); } private void after() { System.out.println("结婚之后收尾款"); } }