简单工厂模式
又在温习设计模式咯,所以把学习的经历写下来..... 我们希望建立一个银行系统,但银行系统应具有一些业务,诸如存款、取款、转账等,通过对这些业务进行抽象,得到一个业务接口: IOperation ,该接口包含一个业务处理的抽象方法operation,如下所示: 1 interface IOperation 2 { 3 void operation(); 4 } 通过该接口实现各个银行功能类: 1 /**/ /// <summary> 2 /// 存款业务处理类 3 /// </summary> 4 class SavingBox:IOperation 5 { 6 public void operation() 7 { 8 Console.WriteLine( " You are saving! " ); 9 } 10 } 11 /**/ /// <summary> 12 /// 取款业务处理类 13 /// </summary> 14 class OutingBox : IOperation 15 { 16 public void operation() 17 { 18 Console.WriteLine( " You are outing! " ); 19 } 20 } 21 /**/ /// <summary> 22 /// 转账业务处理类 23 /// </summary>