zoukankan      html  css  js  c++  java
  • 学习笔录——大话设计模式——外观模式

    学习笔录——设计模式

    外观模式(Facade)

    简介

    为子系统中的一组接口提供一个一致的界面,定义一个高层,这个高层使这一子系统更加容易使用。

    代码示例

    
        /// <summary>
        /// 子系统类1
        /// </summary>
        public class SubSystemOne
        {
            public void SayOne() => System.Console.WriteLine("子系统1");
        }
    
        /// <summary>
        /// 子系统类2
        /// </summary>
        public class SubSystemTwo
        {
            public void SayTwo() => System.Console.WriteLine("子系统2");
        }
    
        /// <summary>
        /// 子系统类3
        /// </summary>
        public class SubSystemThree
        {
            public void SayThree() => System.Console.WriteLine("子系统3");
        }
    
        /// <summary>
        /// 外观类
        /// </summary>
        public class Facade
        {
            SubSystemOne one;
            SubSystemTwo two;
            SubSystemThree three;
            public Facade()
            {
                one = new SubSystemOne();
                two = new SubSystemTwo();
                three = new SubSystemThree();
            }
    
            public void SayOneTwo()
            {
                one.SayOne();
                two.SayTwo();
            }
            public void SayOneThree()
            {
                one.SayOne();
                three.SayThree();
            }
        }
    
        class Program
        {
            static void Main(string[] args)
            {
                var facade = new Facade();
                facade.SayOneThree();
                facade.SayOneTwo();
                Console.Read();
            }
        }
    
    

    个人理解,不足之处还请指教。

    能够让客户端无感到其子系统,只关注于门面。

  • 相关阅读:
    Python的object和type理解及主要对象层次结构
    【译】Matplotlib:plotting
    random
    【译】itertools
    VBA笔记
    Python Function
    Outlook API
    VB参考
    类方法:绑定或无绑定
    【摘录】数据库连接参数
  • 原文地址:https://www.cnblogs.com/caiyangcc/p/13089628.html
Copyright © 2011-2022 走看看