将Facade装饰模式的代码由C#转为JAVA
呵呵,除了输出语句,其它几乎完全一样。
看来都是类C。流着同样的血液。
1 class Stock 2 { 3 public void Sell() 4 { 5 System.out.println("Sell Stock"); 6 } 7 public void Buy() 8 { 9 System.out.println("Buy Stock"); 10 } 11 } 12 13 class NationDebt 14 { 15 public void Sell() 16 { 17 System.out.println("Sell NationDebt"); 18 } 19 public void Buy() 20 { 21 System.out.println("Buy NationDebt"); 22 } 23 } 24 25 class Realty 26 { 27 public void Sell() 28 { 29 System.out.println("Sell Realty"); 30 } 31 public void Buy() 32 { 33 System.out.println("Buy Realty"); 34 } 35 } 36 37 class Fund 38 { 39 Stock st; 40 NationDebt nd; 41 Realty re; 42 43 public Fund() 44 { 45 st = new Stock(); 46 nd = new NationDebt(); 47 re = new Realty(); 48 } 49 50 public void BuyFund() 51 { 52 st.Buy(); 53 nd.Buy(); 54 re.Buy(); 55 } 56 public void SellFund() 57 { 58 st.Sell(); 59 nd.Sell(); 60 re.Sell(); 61 } 62 } 63 class ArrayApp 64 { 65 66 public static void main(String[] args) 67 { 68 Fund fd = new Fund(); 69 fd.BuyFund(); 70 System.out.println("========"); 71 fd.SellFund(); 72 73 } 74 }