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'
    */
     
  • 相关阅读:
    剑指offer-02-替换空格
    剑指offer-03-从尾到头打印链表
    剑指offer-01-二维数组中的查找
    JS-几类函数
    【工具使用】—VSCode
    【工具使用】—Chrome工具使用技巧
    【codeReview】button-disabled
    c语言中结构体位段
    结构体位断
    malloc/free与 new/delete的区别
  • 原文地址:https://www.cnblogs.com/shihao/p/2499954.html
Copyright © 2011-2022 走看看