Facade---外观模式:
1,在设计初期阶段,应该有意识的将不同的层分离。
2,在开发阶段,增加FACADE可以减少类的接口之间的依赖。
3,在维护遗留的大型系统时,为新系统开发一个外观类,让新系统与外观类交互,外观与遗留代码交互所有复杂的工作。
1 /* 2 * Created by SharpDevelop. 3 * User: home 4 * Date: 2013/4/24 5 * Time: 22:18 6 * 7 * To change this template use Tools | Options | Coding | Edit Standard Headers. 8 */ 9 using System;10 11 namespace Facade12 {13 class Stock14 {15 public void Sell()16 {17 Console.WriteLine("股票卖出");18 }19 public void Buy()20 {21 Console.WriteLine("投票买入");22 }23 }24 25 class NationDebt26 {27 public void Sell()28 {29 Console.WriteLine("国债卖出");30 }31 public void Buy()32 {33 Console.WriteLine("国债买入");34 }35 }36 37 class Realty38 {39 public void Sell()40 {41 Console.WriteLine("地产卖出");42 }43 public void Buy()44 {45 Console.WriteLine("地产买入");46 }47 }48 49 class Fund50 {51 Stock st;52 NationDebt nd;53 Realty re;54 55 public Fund()56 {57 st = new Stock();58 nd = new NationDebt();59 re = new Realty();60 }61 public void BuyFund()62 {63 st.Buy();64 nd.Buy();65 re.Buy();66 }67 public void SellFund()68 {69 st.Sell();70 nd.Sell();71 re.Sell();72 }73 }74 75 class Program76 {77 public static void Main(string[] args)78 {79 Fund jijin = new Fund();80 jijin.BuyFund();81 Console.WriteLine("========");82 jijin.SellFund();83 84 Console.ReadKey(true);85 }86 }87 }