重点概念回顾

1.为子系统中的一组接口提供一个一致的界面,此模式定义了一个高层接口,这个接口使得这一个子系统更觉容易使用。

2009-12-01_183417

2. 即使不知道外观模式也一定使用过外观模式,他完美的体现了依赖倒置(面向接口编程)原则和迪米特法则(功能松耦合)的思想,十分常用。

3. 外观模式的核心是,通过将分散的功能包含在外观类中,从而提供一致的操作接口,封装实现,起到了松耦合的目的

4. 在设计的初期阶段,应该要有意识的建立层次上的分离。

5.  可以为封装复杂的接口,也可以为封装众多功能的接口,使用外观模式。

6.  外观模式就是封装复杂。

 

演示例题

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

namespace 外观模式
{
    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 on 2009-12-01 20:41  冯瑞涛  阅读(487)  评论(0编辑  收藏  举报