Facade模式是一种简单的结构,位于更复杂的结构上。
子系统是实现功能但可以被Facade“包装”或“覆盖”以简化接口的任何类或对象。
外观是子系统之上的抽象层,并且知道将适当的工作委派给哪个子系统。
Facade模式是如此的笼统,几乎适用于所有主要应用程序,尤其是那些由于各种原因我无法重构或修改 应用程序的应用程序。
public class HomeFacade { LightsFacade light; MusicSystemFacade musicSystem; AcFacade ac; public HomeFacade() { light = new LightsFacade(); musicSystem = new MusicSystemFacade(); ac = new AcFacade(); } public void LeaveHomeForOffice() { light.SwitchOffLights(); musicSystem.SwitchOffMusicSystem(); ac.SwitchOffAc(); } public void ArriveHomeFromOffice() { light.SwitchOnLights(); musicSystem.SwitchOnMusicSystem(); ac.SwitchOnAc(); } } public class LightsFacade { public void SwitchOnLights() { Console.WriteLine("Switched on Lights"); } public void SwitchOffLights() { Console.WriteLine("Switched off Lights"); } } public class MusicSystemFacade { public void SwitchOnMusicSystem() { Console.WriteLine("Switched on MusicSystem"); } public void SwitchOffMusicSystem() { Console.WriteLine("Switched off MusicSystem"); } } public class AcFacade { public void SwitchOnAc() { Console.WriteLine("Switched on Ac"); } public void SwitchOffAc() { Console.WriteLine("Switched off Ac"); } }