-
what is facade pattern
-
the word facade means a deceptive front or appearance. Following this definition, a facade pattern provides a simpler interface that hides the complex functionalities of a system. This is widely used in JavaScript libraries like jQuery.
-
The facade pattern allows you to hide all the messy logic from the client and only display the clear and easy-to-use interface to them. This allows them to interact with an API easily in a less error-prone way and without accessing the inner workings directly.
-
In plain words
Facade pattern provides a simplified interface to a complex subsystem.
- Wikipedia says
A facade is an object that provides a simplified interface to a larger body of code, such as a class library.
- A simple example of the facade pattern is placing an order at a restaurant. Imagine yourself as a customer who wants to eat at a restaurant. You are the client in this scenario. Depending on the place you go to eat, it’s either the waiter will take your order, or you’ll place it at the counter. Then, you’ll wait for a few minutes and the next thing you know, your food will be served.
- How was your food made? Which chef was assigned the task of making your food? What ingredients were used? How much stock was used or left afterward? Who cleaned the kitchen after your food had been prepared? All of these complexities are hidden from you. These are the unnecessary details that you as a customer, don’t need to know.
Programmatic Example
Taking our computer example from above. Here we have the computer class
Here we have the facade
Now to use the facade