- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What is Facade and how to implement in C#?
The Facade pattern is a simple structure laid over a more complex structure.
The Participants
The Subsystems are any classes or objects which implement functionality but can be "wrapped" or "covered" by the Facade to simplify an interface.
The Facade is the layer of abstraction above the Subsystems, and knows which Subsystem to delegate appropriate work to.
The Facade pattern is so general that it applies to almost every major app especially those where I couldn't refactor or modify pieces of said apps for various reasons.
Example
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"); } }
Advertisements
To Continue Learning Please Login
Login with Google