zoukankan      html  css  js  c++  java
  • facadetheoryns.cs

    using System;

      // Facade Pattern                       Judith Bishop Dec 2006
      // Sets up a library of three systems, accessed through a
      // Facade of two operations
      // Compile with csc /t:library /out:FacadeLib.dll Facade2.cs

      namespace FacadeLib {
        
      internal class SubsystemA {
        internal string A1() {
          return "Subsystem A, Method A1\n";
        }
          
        internal string A2() {
            return "Subsystem A, Method A2\n";
          }
      }

      internal class SubsystemB{
        internal string B1() {
          return "Subsystem B, Method B1\n";
        }
      }
     
      internal class SubsystemC{
        internal string C1() {
          return "Subsystem C, Method C1\n";
        }
      }
     
      public static class Facade {
        static SubsystemA a = new SubsystemA();
        static SubsystemB b = new SubsystemB();
        static SubsystemC c = new SubsystemC();

        public static void Operation1() {
          Console.WriteLine("Operation 1\n" +
          a.A1() +
          a.A2() +
          b.B1());
        }

        public static void Operation2() {
          Console.WriteLine("Operation 2\n" +
          b.B1() +
          c.C1());
        }
      }
    }

    /* Output:

    Operation 1
    Subsystem A, Method A1
    Subsystem A, Method A2
    Subsystem B, Method B1

    Operation 2
    Subsystem B, Method B1
    Subsystem C, Method C1

    */

    /*
    SubsystemC x = new SubsystemC();
    x.C1();
    Facade2Main.cs(12,3): error CS0122: 'FacadeLib.SubsystemC' is inaccessible due to its protection level
    Facade2Main.cs(12,22): error CS0122: 'FacadeLib.SubsystemC' is inaccessible due to its protection level
    Facade2Main.cs(12,18): error CS0143: The type 'FacadeLib.SubsystemC' has no constructors defined
    Facade2Main.cs(13,5): error CS0117: 'FacadeLib.SubsystemC' does not contain a definition for 'C1'
    */
     
  • 相关阅读:
    MySQL中MyISAM为什么比InnoDB查询快
    .Net Core导入千万级数据至Mysql
    细说MySql索引原理
    原生Swagger界面太low(推荐)
    开源分布式调度系统分享(ScheduleMaster)
    tfs agent cicd 自动编译 xcpoy失败
    .net 网站
    Android App Arch
    Android 多进程引发的一次crash
    Scrapy 抓取数据入门操作
  • 原文地址:https://www.cnblogs.com/shihao/p/2499954.html
Copyright © 2011-2022 走看看