2007-05-16

电话面试

     今天接到电话面试,起先问的问题都还可以,之后问了我一个什么叫门面模式,我倒是用过模式,不过没用过门面模式,哪位大哥知道啊?

definiton:
    为子系统中的多个接口提供一个统一的接口,Facade 定义了一个更高层的接口以方便子系统更方便的应用。

UML class diagram


UML Image

sample code in C#

using System;

namespace DoFactory.GangOfFour.Facade.Structural
{

  // Mainapp test application

  class MainApp
  {
    public static void Main()
    {
      Facade facade = new Facade();

      facade.MethodA();
      facade.MethodB();

      // Wait for user
      Console.Read();
    }
  }

  // "Subsystem ClassA"

  class SubSystemOne
  {
    public void MethodOne()
    {
      Console.WriteLine(" SubSystemOne Method");
    }
  }

  // Subsystem ClassB"

  class SubSystemTwo
  {
    public void MethodTwo()
    {
      Console.WriteLine(" SubSystemTwo Method");
    }
  }

  // Subsystem ClassC"

  class SubSystemThree
  {
    public void MethodThree()
    {
      Console.WriteLine(" SubSystemThree Method");
    }
  }

  // Subsystem ClassD"

  class SubSystemFour
  {
    public void MethodFour()
    {
      Console.WriteLine(" 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()
    {
      Console.WriteLine("\nMethodA() ---- ");
      one.MethodOne();
      two.MethodTwo();
      four.MethodFour();
    }

    public void MethodB()
    {
      Console.WriteLine("\nMethodB() ---- ");
      two.MethodTwo();
      three.MethodThree();
    }
  }
}    


Output
MethodA() ----
SubSystemOne Method
SubSystemTwo Method
SubSystemFour Method

MethodB() ----
SubSystemTwo Method
SubSystemThree Method
评论
lifangxing 2008-04-07   回复
Java与模式里面好像就是写门面模式
小小龙猫 2007-05-16   回复
我希望我听错了,然后我还问了一下,是门面模式么?也许他也听错了,反正回答我说是的.
ouspec 2007-05-16   回复
门面模式?楼主听错了吧。
发表评论

您还没有登录,请登录后发表评论

小小龙猫
搜索本博客
存档
最新评论