定义:为子系统中的一组接口提供一个一致的界面,此模式定义了一个高级接口,这个接口使得这一个子系统更加容易使用。
首先,在设计初期阶段,应该要有意识的将不同的层分离。其次,在开发阶段,子系统往往因为不断的重构演化而变得复杂,增加外观类可以提供一个简单的接口,减少他们的依赖。第三,在维护一个遗留的大型系统时,可能这个系统已经非常难以维护和发展了,开发一个外观类,来提供设计粗糙或高度复杂的遗留代码的比较清晰简单的接口,让新系统与外观类对象交互,外观类与遗留代码交互所有复杂的工作
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace 外观模式
{
class SubOne
{
public void Methed1()
{
Console.WriteLine("11");
}
}
class SubTwo
{
public void Methed2()
{
Console.WriteLine("22");
}
}
class SubThree
{
public void Methed3()
{
Console.WriteLine("33");
}
}
class Facede
{
SubOne one;
SubTwo two;
SubThree three;
public Facede()
{
one = new SubOne();
two = new SubTwo();
three = new SubThree();
}
public void MethodA()
{
Console.WriteLine("A:");
one.Methed1();
two.Methed2();
}
public void MethodB()
{
Console.WriteLine("B:");
two.Methed2();
three.Methed3();
}
}
class Program
{
static void Main(string[] args)
{
Facede faced = new Facede();
faced.MethodA();
faced.MethodB();
Console.Read();
}
}
}