zoukankan      html  css  js  c++  java
  • 外观模式

    外观模式 (Facade):为子系统的一组接口提供一个一致的界面,此模式定义了一个高层接口,此接口使此子系统更加容易使用;

     1  class Program
     2     {
     3         static void Main(string[] args)
     4         {
     5             Facade facade = new Facade();
     6 
     7             facade.MethodA();
     8             facade.MethodB();
     9 
    10             Console.Read();
    11 
    12         }
    13     }
    14 
    15     class SubSystemOne
    16     {
    17         public void MethodOne()
    18         {
    19             Console.WriteLine(" 子系统方法一");
    20         }
    21     }
    22 
    23     class SubSystemTwo
    24     {
    25         public void MethodTwo()
    26         {
    27             Console.WriteLine(" 子系统方法二");
    28         }
    29     }
    30 
    31     class SubSystemThree
    32     {
    33         public void MethodThree()
    34         {
    35             Console.WriteLine(" 子系统方法三");
    36         }
    37     }
    38 
    39     class SubSystemFour
    40     {
    41         public void MethodFour()
    42         {
    43             Console.WriteLine(" 子系统方法四");
    44         }
    45     }
    46 
    47     class Facade
    48     {
    49         SubSystemOne one;
    50         SubSystemTwo two;
    51         SubSystemThree three;
    52         SubSystemFour four;
    53 
    54         public Facade()
    55         {
    56             one = new SubSystemOne();
    57             two = new SubSystemTwo();
    58             three = new SubSystemThree();
    59             four = new SubSystemFour();
    60         }
    61 
    62         public void MethodA()
    63         {
    64             Console.WriteLine("
    方法组A() ---- ");
    65             one.MethodOne();
    66             two.MethodTwo();
    67             four.MethodFour();
    68         }
    69 
    70         public void MethodB()
    71         {
    72             Console.WriteLine("
    方法组B() ---- ");
    73             two.MethodTwo();
    74             three.MethodThree();
    75         }
    76     }
    输出:
    
    方法组A() ----
     子系统方法一
     子系统方法二
     子系统方法四
    
    方法组B() ----
     子系统方法二
     子系统方法三
    

     

     

  • 相关阅读:
    推荐几个漂亮实用的JS菜单
    让文字与input居中对齐
    CSS的优先级特性
    博客园2007年度工作总结
    一些页面自动跳转的实现
    C#中的数字格式化、格式日期格式化[转]
    phpBB 3.07 bug 以及 phpBB bug tracker的bug
    Checkout Now Alipay.com
    不敢再用QQ邮箱、Foxmail
    已修复Tree Style Tab XML解析错误(Tree Style Tab 0.10.2010040201)
  • 原文地址:https://www.cnblogs.com/liuke-1264746554/p/10601281.html
Copyright © 2011-2022 走看看