facadestructural.cs

来自「使用C#程序将23个常用设计模式进行列表显示」· CS 代码 · 共 91 行

CS
91
字号
using System;
using System.Windows.Forms;
using System.Text;

namespace DesignPattern.FacadeStructural
{
    class FacadeStructural : AbstractPattern
    {
        public static void Run(TextBox tbInfo)
        {
            s_tbInfo = tbInfo;
            s_tbInfo.Text = "";

            Facade facade = new Facade(); 
            facade.MethodA(); 
            facade.MethodB();
            
            // Wait for user 
            //Console.Read();
        }
    }
    
    // "Subsystem ClassA" 
    class SubSystemOne 
    {
        public void MethodOne() 
        {
            DesignPattern.FormMain.OutputInfo(" SubSystemOne Method"); 
        }
    }
    
    // Subsystem ClassB" 
    class SubSystemTwo 
    {
        public void MethodTwo()
        { 
            DesignPattern.FormMain.OutputInfo(" SubSystemTwo Method"); 
        }
    } 
    
    // Subsystem ClassC" 
    class SubSystemThree 
    {
        public void MethodThree() 
        {
            DesignPattern.FormMain.OutputInfo(" SubSystemThree Method"); 
        }
    }
    
    // Subsystem ClassD" 
    class SubSystemFour 
    {
        public void MethodFour() 
        {
            DesignPattern.FormMain.OutputInfo(" SubSystemFour Method"); 
        }
    }
    
    // "Facade" 
    class Facade 
    {
        SubSystemOne one; 
        SubSystemTwo two;
        SubSystemThree three; 
        SubSystemFour four; 
        
        public Facade() 
        {
            one = new SubSystemOne(); 
            two = new SubSystemTwo(); 
            three = new SubSystemThree(); 
            four = new SubSystemFour(); 
        }
        
        public void MethodA() 
        {
            DesignPattern.FormMain.OutputInfo("\nMethodA() ---- ");
            one.MethodOne(); 
            two.MethodTwo(); 
            four.MethodFour();
        } 
        
        public void MethodB() 
        {
            DesignPattern.FormMain.OutputInfo("\nMethodB() ---- "); 
            two.MethodTwo();
            three.MethodThree(); 
        }
    }
}

⌨️ 快捷键说明

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