Design patterns: Facade

In this article about the Facade design pattern , whose main task is to make the complex system available to the customer in the form of a simplified, ordered programming interface.


Description and implementation method

We implement the facade in the form of one class, which is associated with other classes of the complex system, to call the methods of the related classes. Often you can find a facade in large systems, in corporations, that is where you need a simple way to access different data.

And Facade facilitates access to various objects and hides details of the implementation, and this is good because the client does not care how exactly the system is implemented, he only wants to have access to the data that interests him.

An example of implementation can be eg a banking system in which we only have access to some system functions, transfers, account balance, etc.



The following diagram well describes the facade:

Facade scheme

It means that the facade provides one class for using software mass.

Let’s also look at another diagram below:

Facade scheme

We see that we have different classes and every class knows the class of the facade, so it provides a simplified interface in the class to use all of these classes, the client does not need to know the exact details of the implementation.



Bank facade

Let’s now see what the facade looks like in a practical example of life taken.

Our task is to create a bank account simulator, that is, we have to create an API shared with the client:

It is much easier to use the API than to refer to individual parts of the system, also the system is much safer because the client does not have access to the entire system.

For remind the solid principles and dependency injection principle, let’s use the container from the dependency injection lesson to register class instances in the constructor and not to create them rigidly.

Now it is more in line with solid and dependency injection and generally with the principles of code cleanliness.



The facade of creating a car

In this example, we’ll make an example of creating a car, this example will be very similar to the previous one, let’s start with the classes that make up the individual parts of the car.

Many of these classes and the clients are not interested in their exact implementation, which is why we have a facade class that simplifies the use of these classes.

By using dependency Injection principle, we inject dependencies in the constructor and create a car using only one CreateCompleteCar() method, so that the client does not have to delve into the details of the implementation and will be probably thankful for our facade class.

The call in the client looks like this:



Advantages and disadvantages


  • Reduces the number of dependencies between the customer and the system, the whole is easier to maintain and maintenance if the customer does not use individual parts of the system.
  • Application is split into layers, separate client and system development.
  • The ability to block the client access to some of the system’s functionalities.


  • I don’t think there are any …


Relations with other design patterns

  • Facade creates a new interface that simplifies the use of existing functionalities, the adapter creates an interface that works with the old interface.
  • Flyweight shows how to make a lot of small objects, the facade shows how to make one object representing the whole system.
  • The mediator is similar to the facade in that it simplifies the existing functionality, but differs in that the Mediator only simplifies communication between classes and Facade creates an interface, thanks to which it will simply be easier to use existing functionalities.
  • Facade objects are often singletons, because only one object is needed in the facade pattern.



That’s all about Facade 🙂.

As you can see the Facade design pattern is very useful, now we can, for example, choose which parts of the system to share, for example our colleague in the team, so that he does not have to know what exactly he does, just that he could use it immediatly.

Link to github with the whole code from this article:

This content also you can find on my steemit blog

And on medium:

In the next article, we will talk about the Composite pattern.

As a standard, I remind you about the newsletter, which I send notifications about new entries and additional information about the IT world in general.🙂

And NECESSERILY join the DevmanCommunity community on fb, part of the community is in one place 🙂

– site on fb:ławomir Kowalski

– group on fb: DevmanCommunity

Ask, comment underneath at the end of the post, share it, rate it, whatever you want🙂.

If that post was useful for you share it with your friends :)

Post a comment

Notify about