I am here to continue the discussion around design patterns. Today, we will go through one of the structural design patterns called Facade.
Before talking about its implementation, let’s begin by defining it.
As per GOF guys, Facade pattern is defined as:
“Provide a unified interface to a set of interfaces in a subsystem. Façade defines a higher-level interface that makes the subsystem easier to use.”
All right! Let’s understand what they mean.
It means that when you have several sub-systems or classes, it’s often difficult for a client to interact with all of them, and if somehow the client manages to interact, the code becomes messy and difficult to maintain for any future change.
How Façade pattern works
Facade addresses the same problem by having just one interface (or wrapper class) to interact with client for all of its need. The wrapper class, internally handles all the complexity of interactions with other sub-systems.
Let’s understand this by a simple example.
We will take the same car example to illustrate the concept.
Let’s begin with building the sub-systems classes as in the following:
- class Body
- {
- public void AssembleBody()
- {
- Console.WriteLine("Assembling Body...");
- }
- }
- class Engine
- {
- public void AssembleEngine()
- {
- Console.WriteLine("Assembling Engine...");
- }
- }
- class Tyre
- {
- public void AssembleTyre()
- {
- Console.WriteLine("Assembling Tyre...");
- }
- }
- class Accessories
- {
- public void AssembleSeat()
- {
- Console.WriteLine("Assembling Seat...");
- }
- public void AssembleMusicSystem()
- {
- Console.WriteLine("Assembling Music System...");
- }
- }
So, the sub-system is built now. Now, let’s design our Facade class which will talk to the client by some public methods exposed by it.
- class CarFacade
- {
- Body body;
- Engine engine;
- Tyre tyre;
- Accessories accessories;
- public CarFacade()
- {
- body = new Body();
- engine = new Engine();
- tyre = new Tyre();
- accessories = new Accessories();
- }
- public void AssembleCar()
- {
- Console.WriteLine("Car Assembling Started...");
- body.AssembleBody();
- engine.AssembleEngine();
- tyre.AssembleTyre();
- accessories.AssembleSeat();
- accessories.AssembleMusicSystem();
- Console.WriteLine("Car Assembling Done...");
- }
- }
Now all the required setup is ready, let’s see how client uses this.
- static void Main()
- {
- Console.Title = "Facade pattern demo";
- CarFacade carFacade = new CarFacade();
- carFacade.AssembleCar();
- }
Output
So as you can see that client only knows about a façade method called AssembleCar and is successfully able to assemble the car without going into the complexity of various sub-systems involved.
Class Diagram
Hope you have liked the article. Look forward for your comments/suggestions.
Links to previous articles
- Design Patterns Simplified: Part 1
- Design Patterns Simplified - Part 2 (Singleton)
- Design Patterns Simplified - Part 3 (Simple Factory)
- Design Patterns Simplified - Part 4 (Abstract Factory)
- Design Patterns Simplified - Part 5 (Factory Method)
- Design Patterns Simplified - Part 6 (Prototype)
- Design Patterns Simplified - Part 7 (Builder)


Prakash TripathiTOP 100Posted Apr 9, 2016, 6:42 AM EDT
Thnx Nagaraj.
Kuppurasu NagarajTOP 100Posted Apr 9, 2016, 6:37 AM EDT
Nice article..
Prakash TripathiTOP 100Posted Mar 6, 2016, 6:01 PM EST
Thnx Kumaresh.
Prakash TripathiTOP 100Posted Mar 6, 2016, 6:00 PM EST
Thnx Karthiga.
Kumaresh RajalingamPosted Mar 6, 2016, 3:29 PM EST
good one
Kumaresh RajalingamPosted Mar 6, 2016, 3:29 PM EST
Nice explanation
Sr KarthigaPosted Mar 6, 2016, 3:18 PM EST
good one
Sr KarthigaPosted Mar 6, 2016, 3:18 PM EST
Nice explanation
Prakash TripathiTOP 100Posted Jan 27, 2016, 3:34 PM EST
Thnx sthitaprajnya.
Prakash TripathiTOP 100Posted Jan 27, 2016, 3:33 PM EST
Thnx Santhakumar.
Sthitaprajnya Debasis NayakPosted Jan 27, 2016, 10:40 AM EST
Very Much Helpful Article !!!
Santhakumar MunuswamyPosted Jan 27, 2016, 8:57 AM EST
Thanks for nice share
Prakash TripathiTOP 100Posted Jan 27, 2016, 5:01 AM EST
@Maruthi, feel free to get back to me if u have any specific question.
Prakash TripathiTOP 100Posted Jan 27, 2016, 2:04 AM EST
Thnx Ankit.
Ankit BansalPosted Jan 27, 2016, 1:15 AM EST
Nice share..thanks..
Prakash TripathiTOP 100Posted Jan 27, 2016, 1:08 AM EST
Thnx Humayun.
Prakash TripathiTOP 100Posted Jan 27, 2016, 1:08 AM EST
Thnx Aqib.
Humayun Kabir MamunPosted Jan 27, 2016, 12:26 AM EST
Nice...
Muhammad Aqib ShehzadPosted Jan 27, 2016, 12:24 AM EST
fabulous article
Prakash TripathiTOP 100Posted Jan 26, 2016, 10:45 PM EST
@Maruthi, Basically it's simplify the interactions between client and business logic by exposing concrete methods. It's useful when there are several sub-systems involved. In the absence of this pattern client had to make lot of interactions which is not just costly but also messy. Hope this clarifies.
Prakash TripathiTOP 100Posted Jan 26, 2016, 10:31 PM EST
Thnx Ibrahim.
Mohammed IbrahimPosted Jan 26, 2016, 10:23 PM EST
nice
Maruthi PalllamalliPosted Jan 26, 2016, 10:08 PM EST
I am so much interested on design patterns. We can solve so many problems by using Design Patterns. So what kind of problems we can solve with Facade design pattern ?