![]() |
The Facade Pattern is a structural design pattern that provides a unified interface for a set of interfaces in a subsystem. This pattern simplifies the use of a complex system by hiding its complexity behind a single access interface. The main goal is to improve code readability and reduce dependencies between components.
Pattern Family: Structural Patterns
The Facade Pattern belongs to the family of structural design patterns. Structural patterns focus on organizing classes and objects to facilitate software design, improve maintainability, and reduce dependencies between components.
Diagram
![]() |
How the Facade Pattern Works
To better understand how the Facade pattern works, imagine that we have a complex audio-video system with multiple components, such as a Blu-ray player, a projector, and a surround sound system. To turn on the system and play a movie, you need to:
Turn on the projector
Set the source to the Blu-ray player
Turn on the Blu-ray player
Turn on the audio system
Set the volume
If every action was performed directly by the user interacting with each individual component, the code would be difficult to maintain. With the Facade pattern, we can create a HomeTheaterFacade class that encapsulates these operations and provides a simplified method:
Now, instead of interacting with each individual component, we can simply call:
A more concrete example: Online payments
Suppose we need to implement an online payment system. This system involves several operations:
Checking the availability of funds
Payment Processing
Sending the receipt
Without the Facade pattern, application code would have to interact directly with each service, increasing complexity and the risk of errors. Using the Facade pattern, we can create a class that hides implementation details:
Now, to process a payment, the application can simply call:
Follow me #techelopment
Official site: www.techelopment.it
facebook: Techelopment
instagram: @techelopment
X: techelopment
Bluesky: @techelopment
telegram: @techelopment_channel
whatsapp: Techelopment
youtube: @techelopment