外觀模式

爲子系統中的一組接口提供一個一致的調用接口,此模式定義了一個高層接口,這個接口使得這一子系統更加容易使用;

實現代碼:

  internal class SystemOne
    {
        public void MethodOne()
        {
            Console.WriteLine("系統一的方法");
        }
    }

    internal class SystemTwo
    {
        public void MethodTwo()
        {
            Console.WriteLine("系統二的方法");
        }
    }

    internal class SystemThree
    {
        public void MethodThree()
        {
            Console.WriteLine("系統三的方法");
        }
    }

    internal class SystemFour
    {
        public void MethodFour()
        {
            Console.WriteLine("系統四的方法");
        }
    }

    internal class SystemFive
    {
        public void MethodFive()
        {
            Console.WriteLine("系統五的方法");
        }
    }

    public class Facade
    {
        SystemOne one = new SystemOne();
        SystemTwo two = new SystemTwo();
        SystemThree three = new SystemThree();
        SystemFour four = new SystemFour();
        SystemFive five = new SystemFive();

        public void One()
        {
            one.MethodOne();
            three.MethodThree();
        }

        public void Two()
        {
            two.MethodTwo();
            four.MethodFour();
        }

        public void Three()
        {
            five.MethodFive();
        }
    }

客戶端調用代碼:


            Facade facade = new Facade();
            facade.One();
            facade.Three();

發佈了41 篇原創文章 · 獲贊 7 · 訪問量 14萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章