Facade Design Pattern in Java

This design pattern comes under structural pattern as this pattern adds an interface to the existing system to hide all its complexities. As the name suggests Facade means the face of the building block.

The real life examples of this pattern can be explained as explained below :

We know that Computer system starts up when we push a start button on the CPU but we do not know how that start button sends signal to other internal circuits to actually boot the computer system. So the Facade pattern just gives us a friendly start button to start up the computer and hides all internal complexities of how it happens.
We can also take an another example of starting a car. We just push the key and start the ignition switch to start the car and we are not bother about how that ignition switch (sends signal to other internal circuits) starts the car.

This is how facade pattern is used. It hides the complexities of the system and provides an interface to the client from where the client can access the system.
Design pattern of JDBC can be called as a facade pattern. Clients create connection using the java.sql.Connection interface, the implementation of which clients are not concerned about. The implementation is left to the vendor of driver.

Let’s try and understand the facade pattern better using a simple example. Let’s consider a starting mechanism of a car engine. We will see how car engine starts up once we turns the ignition switch on to the car. Continue reading “Facade Design Pattern in Java”