【C#设计模式(11)——外观模式(Facade Pattern)】
前言
外观模式隐藏了子系统的复杂性,简化了客户端与子系统之间的交互。
代码
public class Facade
{
private CommunicationModel communicationModel;
private AcquisitionModel acquisitionModel;
private ToolModel toolModel;
public Facade()
{
communicationModel = new CommunicationModel();
acquisitionModel = new AcquisitionModel();
toolModel = new ToolModel();
}
public void Load()
{
communicationModel.Load();
acquisitionModel.Load();
toolModel.Load();
}
}
// 通讯模块
public class CommunicationModel
{
public void Load()
{
Console.WriteLine("Load communication model...");
}
}
// 采集模块
public class AcquisitionModel
{
public void Load()
{
Console.WriteLine("Load acquisition model...");
}
}
//工具模块
public class ToolModel
{
public void Load()
{
Console.WriteLine("Load tool model...");
}
}
/*
* 结构型模式:Structural Pattern
* 外观模式:Facade Pattern
*/
internal class Program
{
static void Main(string[] args)
{
Facade facade = new Facade();
facade.Load();
Console.ReadLine();
}
}