标签:
结构 | |
意图 | 为子系统中的一组接口提供一个一致的界面,F a c a d e 模式定义了一个高层接口,这个接口使得这一子系统更加容易使用。 |
适用性 |
|
1 using System; 2 3 class SubSystem_class1 4 { 5 public void OperationX() 6 { 7 Console.WriteLine("SubSystem_class1.OperationX called"); 8 } 9 } 10 11 class SubSystem_class2 12 { 13 public void OperationY() 14 { 15 Console.WriteLine("SubSystem_class2.OperationY called"); 16 } 17 } 18 19 class SubSystem_class3 20 { 21 public void OperationZ() 22 { 23 Console.WriteLine("SubSystem_class3.OperationZ called"); 24 } 25 } 26 27 class Facade 28 { 29 private SubSystem_class1 c1 = new SubSystem_class1(); 30 private SubSystem_class2 c2 = new SubSystem_class2(); 31 private SubSystem_class3 c3 = new SubSystem_class3(); 32 33 public void OperationWrapper() 34 { 35 Console.WriteLine("The Facade OperationWrapper carries out complex decision-making"); 36 Console.WriteLine("which in turn results in calls to the subsystem classes"); 37 c1.OperationX(); 38 if (1==1 /*some really complex decision*/) 39 { 40 c2.OperationY(); 41 } 42 // lots of complex code here . . . 43 c3.OperationZ(); 44 } 45 46 } 47 48 /// <summary> 49 /// Summary description for Client. 50 /// </summary> 51 public class Client 52 { 53 public static int Main(string[] args) 54 { 55 Facade facade = new Facade(); 56 Console.WriteLine("Client calls the Facade OperationWrapper"); 57 facade.OperationWrapper(); 58 return 0; 59 } 60 }
标签:
原文地址:http://www.cnblogs.com/ziranquliu/p/4663318.html