1 package org.study2.javabase.ThreadsDemo.staticproxy; 2 3 /** 4 * @Date:2018-09-18 静态代理 设计模式 5 * 1、真实角色 6 * 2、代理角色:持有真实角色的引用 7 * 3、二者实现相同的接口 8 * 举例说明:Couple类和Company类都实现了Marry,通过Company类实际操作Couple类的marry方法。 9 */ 10 public class StaticProxy { 11 public static void main(String args[]) { 12 Couple couple = new Couple(); 13 Company company = new Company(couple); 14 company.marry(); 15 } 16 } 17 18 interface Marry { 19 public abstract void marry(); 20 } 21 22 class Couple implements Marry { 23 24 @Override 25 public void marry() { 26 System.out.println("我们结婚啦!"); 27 } 28 } 29 30 class Company implements Marry { 31 private Couple couple; 32 33 public Company() { 34 35 } 36 37 public Company(Couple couple) { 38 this.couple = couple; 39 } 40 41 @Override 42 public void marry() { 43 System.out.println("婚庆公司准备中。。。"); 44 couple.marry(); 45 System.out.println("婚礼结束 ,婚庆公司收摊。。。"); 46 } 47 }