外观模式,也叫门面模式,是一种通过减少系统中各个组件之间的交互来简化复杂系统的模式。该模式隐藏了系统的复杂性,使系统内部组件的调用更加方便,同时也降低了代码的耦合度,便于代码的维护和升级。
以下是使用C#实现的外观模式的示例代码:
using System;
namespace FacadePatternDemo
{
class Program
{
static void Main(string[] args)
{
ShapeMaker shapeMaker = new ShapeMaker();
shapeMaker.drawCircle();
shapeMaker.drawRectangle();
shapeMaker.drawSquare();
Console.ReadKey();
}
}
public interface Shape
{
void draw();
}
public class Rectangle : Shape
{
public void draw()
{
Console.WriteLine("Rectangle::draw()");
}
}
public class Square : Shape