In our previous blogs, we have discussed several Structural design patterns i.e., Decorator design pattern, Adapter design pattern and Proxy design pattern.
In this blog, we will be discussing Facade Design pattern and will try to implement it in Scala.
We recently had a tour to Udaipur from our office and to organize it, we inquired a travel agency and asked them to share the quotations. Their quotation was dependent on several factors like category(Group, Family, Honeymoon) and package (Silver, Gold, Platinum).
On the basis of the choice of all these factors, the Booking process was initiated for which they used the Tour and Travel Management application.
This application includes several subsystems, few of them are :
- Ticket Booking
- Hotel Booking
- Booking a vehicle for sightseeing
- Booking Tour Guide
To use these subsystems, our client can directly interact with it. But there is a problem with this approach, i.e., if there is any change in the subsystem like adding/updating/ deleting of a new Service in the subsystem, then we will also have to make changes in the client application, which is not a good approach.
Here comes the role of the Facade design pattern.
What is the Facade Design pattern?
A facade design pattern is a structural design pattern and is commonly used with object-oriented programming.
Facade Design Pattern provides a unified interface to a set of interfaces in a subsystem. Facade defines a higher-level interface that makes the subsystem easier to use.
A facade design pattern is generally used by the developers when a system is very complex or difficult to understand or when the system has a large number of interdependent classes or probably when its source code is unavailable.
This pattern helps in hiding the complexities of the large system and providing a simple interface to the client.
We can create a Facade class as an interface between the Client and our Subsystems. In that way, the Client will interact with the Facade and our Facade class will interact with the subsystems instead of the client directly interacting with the Subsystems.
Hope you liked the blog. Thanks for reading!