設計模式--外觀模式

外觀模式用例圖

 

 

外觀模式的基本代碼

    class Program

    {

        static void Main(string[] args)

        {

            Facade facade = new Facade();

 

            facade.MethodA();

            facade.MethodB();

 

            Console.Read();

 

        }

    }

 

    class SubSystemOne

    {

        public void MethodOne()

        {

            Console.WriteLine(" 子系统方法一");

        }

    }

 

    class SubSystemTwo

    {

        public void MethodTwo()

        {

            Console.WriteLine(" 子系统方法二");

        }

    }

 

    class SubSystemThree

    {

        public void MethodThree()

        {

            Console.WriteLine(" 子系统方法三");

        }

    }

 

    class SubSystemFour

    {

        public void MethodFour()

        {

            Console.WriteLine(" 子系统方法四");

        }

    }

 

    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()

        {

            Console.WriteLine("\n方法组A() ---- ");

            one.MethodOne();

            two.MethodTwo();

            four.MethodFour();

        }

 

        public void MethodB()

        {

            Console.WriteLine("\n方法组B() ---- ");

            two.MethodTwo();

            three.MethodThree();

        }

    }

 

 

posted @ 2016-03-11 11:47  好好學習  阅读(164)  评论(0编辑  收藏  举报