博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
facade-theory-ns.cs
阅读量:5130 次
发布时间:2019-06-13

本文共 1562 字,大约阅读时间需要 5 分钟。

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'
*/
 

转载于:https://www.cnblogs.com/shihao/archive/2012/05/14/2499954.html

你可能感兴趣的文章
sencha touch在华为emotion ui 2.0自带浏览器中圆角溢出的bug
查看>>
【架构】Linux的架构(architecture)
查看>>
ASM 图解
查看>>
Date Picker控件:
查看>>
你的第一个Django程序
查看>>
grafana授权公司内部邮箱登录 ldap配置
查看>>
treegrid.bootstrap使用说明
查看>>
[Docker]Docker拉取,上传镜像到Harbor仓库
查看>>
javascript 浏览器类型检测
查看>>
nginx 不带www到www域名的重定向
查看>>
记录:Android中StackOverflow的问题
查看>>
导航,头部,CSS基础
查看>>
[草稿]挂载新硬盘
查看>>
[USACO 2017 Feb Gold] Tutorial
查看>>
关于mysql中GROUP_CONCAT函数的使用
查看>>
OD使用教程20 - 调试篇20
查看>>
Java虚拟机(JVM)默认字符集详解
查看>>
Java Servlet 过滤器与 springmvc 拦截器的区别?
查看>>
(tmp >> 8) & 0xff;
查看>>
linux命令之ifconfig详细解释
查看>>