CSharp设计模式读书笔记(11):外观模式(学习难度:★☆☆☆☆,使用频率:★★★★★)

定义:

外观模式:为子系统中的一组接口提供一个统一的入口。外观模式定义了一个高层接口,这个接口使得这一子系统更加容易使用。

模式角色与结构:

示例代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CSharp.DesignPattern.FacadePattern
{
    class Program
    {
        static void Main(string[] args)
        {
            Facade facade = new Facade(); //还可以增加一个抽象外观类,然后通过配置文件决定具体外观类
            facade.Method();
        }
    }

    class Facade
    {
        private SubSystemA obj1 = new SubSystemA();
        private SubSystemB obj2 = new SubSystemB();
        private SubSystemC obj3 = new SubSystemC();

        public void Method()
        {
            obj1.MethodA();
            obj2.MethodB();
            obj3.MethodC();
        }
    }

    class SubSystemA
    {
        public void MethodA()
        { }
    }

    class SubSystemB
    {
        public void MethodB()
        { }
    }

    class SubSystemC
    {
        public void MethodC()
        { }
    }
}
原文地址:https://www.cnblogs.com/thlzhf/p/3993377.html