设计模式--外观模式

来源:互联网 发布:java布尔类型 编辑:程序博客网 时间:2024/04/29 18:01

 

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. namespace ConsoleApplication1
  5. {
  6.     class Facade
  7.     {
  8.         private Func1 field1;
  9.         private Func2 field2;
  10.         public Facade()
  11.         {
  12.             field1 = new Func1();
  13.             field2 = new Func2();
  14.         }
  15.         public void Method()
  16.         {
  17.             field1.Method();
  18.             field1.Method1();
  19.             field2.Method();
  20.         }
  21.         public void Method1()
  22.         {
  23.             field2.Method();
  24.             field2.Method1();
  25.             field1.Method();
  26.         }
  27.     }
  28.     class Func1
  29.     {
  30.         public void Method()
  31.         {
  32.             Console.WriteLine("功能类1的方法1");
  33.         }
  34.         public void Method1()
  35.         {
  36.             Console.WriteLine("功能类1的方法2");
  37.         }
  38.     }
  39.     internal class Func2
  40.     {
  41.         public void Method()
  42.         {
  43.             Console.WriteLine("功能类2的方法1");
  44.         }
  45.         public void Method1()
  46.         {
  47.             Console.WriteLine("功能类2的方法2");
  48.         }
  49.     }
  50.     class Client
  51.     {
  52.         public static  void Main()
  53.         {
  54.             Facade f = new Facade();
  55.             f.Method();
  56.             f.Method1();
  57.             Console.Read();
  58.         }
  59.     }
  60. }