
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
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"); } }
- Related Articles
- What is Liskov Substitution principle and how to implement in C#?
- What is dependency inversion principle and how to implement in C#?
- What is Proactive Customer Service and How to Implement It?
- What is Interface segregation principle and how to implement it in C#?
- What is proxy design pattern and how to implement it in C#?
- What is Killer Bees Financial Strategy and How to implement it?
- How to implement MAX(distinct…) in MySQL and what is the difference without using DISTINCT?
- What is interpolation and how can we implement it in the SciPy Python library?
- How to implement expand and collapse notification in Android?
- What is agriculture implement, and why it's important?
- How semaphore is used to implement mutual exclusion?
- How to implement Continuous Integration and Continuous Delivery
- How to implement constants in java?
- How to implement Polymorphism in JavaScript?
- How to implement hooks in Cypress?

Advertisements