静态代理
1 //静态代理 2 public class Test01 { 3 public static void main(String args[]) { 4 new WeddingCompany(new You()).happyMarry(); 5 } 6 } 7 8 interface Marry{ 9 void happyMarry(); 10 } 11 class You implements Marry{ 12 @Override 13 public void happyMarry() { 14 System.out.println("结婚"); 15 } 16 } 17 class WeddingCompany implements Marry{ 18 private Marry target; 19 20 public WeddingCompany(Marry target) { 21 this.target = target; 22 } 23 24 @Override 25 public void happyMarry() { 26 before(); 27 this.target.happyMarry(); 28 } 29 30 private void before() { 31 System.out.println("事前准备"); 32 } 33 }