facade.cs

来自「C#设计模式源码」· CS 代码 · 共 91 行

CS
91
字号
using System;
using System.Collections.Generic;
using System.Text;

namespace DesignDll
{

    /************************************************************************
     * 外观模式;(Facade Method) 为子系统中的一组接口提供一个一致的界面,此模式定
     * 义了一个高层的接口,这个接口使得这一子系统更加容易使用
     * **********************************************************************/

    /// <summary>
    /// 子系统A
    /// </summary>
    public class SubSystemA 
    {
        public string MethodA()
        {
            return "调用SubSystemA的方法";
        }
    }

    /// <summary>
    /// 子系统B
    /// </summary>
    public class SubSystemB
    {
        public string MethodB()
        {
             return "调用SubSystemB的方法";
        }
    }

    /// <summary>
    /// 子系统C
    /// </summary>
    public class SubSystemC
    {
        public string MethodC()
        {
             return "调用SubSystemC的方法";
        }
    }

    /// <summary>
    /// 子系统D
    /// </summary>
    public class SubSystemD
    {
        public string MethodD()
        {
             return "调用SubSystemD的方法";
        }
    }

    /// <summary>
    /// 外观模式
    /// </summary>
    public class Facade
    {
        SubSystemA SystemA;
        SubSystemB SystemB;
        SubSystemC SystemC;
        SubSystemD SystemD;
        public List<string> ls ;
        public Facade()
        {
            SystemA = new SubSystemA();
            SystemB = new SubSystemB();
            SystemC = new SubSystemC();
            SystemD = new SubSystemD();
            ls = new List<string>();
        }

        public void FacadeMethodA()
        {
            ls.Add(SystemA.MethodA());
            ls.Add(SystemB.MethodB());
        }

        public void FacadeMethodB()
        {
            ls.Add(SystemA.MethodA());
            ls.Add(SystemC.MethodC());
            ls.Add(SystemD.MethodD());
        }
    }

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?