?
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 }
?