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() ----
     子系统方法二
     子系统方法三
    

     

     

  • 相关阅读:
    hdu_6836 Expectation
    hdu_6820 Tree
    luogu P1039 侦探推理
    自己动手实现区块链
    第六章 钱包管理界面和区块链浏览器
    第五章 自己动手写比特币之交易中继
    第四章 自己动手写比特币之钱包
    第三章 自己动手写区块链之交易
    第二章 工作量证明和挖矿
    第一章:最小可行区块链
  • 原文地址:https://www.cnblogs.com/liuke-1264746554/p/10601281.html
Copyright © 2011-2022 走看看