Facade Design Pattern in C#.Net

Facade Design Pattern comes under Structural Design Pattern. In short, Facade means the exterior appearance. It means in Facade design pattern we hide something and show only what actually client requires.

If you are new to Design Pattern, please read my earlier blog - Design Pattern in ASP.Net

What is Facade Design Pattern?
Facade design Pattern is used to make a complex system easier.

So basically when and how to implement Facade Design Pattern?
Facade Design Pattern should be implemented -
When a system is more complex with a large number of classes.

In Facade Design Pattern client does not need to know all classes or subsystems to work. A client only requires a Facade class which will automatically call connected subsystems and classes internally.

For eg- If you buy a product from any e-commerce website, you just log in to the system, select your product and place the order. You even don't know whats going on behind the screen.

There could be various logic running behind the screen.

1. Checking inventory
2. Checking nearest warehouse location.
3. Checking any offer/discount for the customer.
4. Payment system

and much more.


Below picture explains about Facade Design Pattern.
Facade Design Pattern in C#
You can see in above example that Client 1,2,3,....n will only connect Order Management class which implements Facade Design Pattern. And then Order Management class will call subsystem1 and susbsytem2 based on business logic implemented in the system.

Comments

Popular