All posts
Published in design patterns

Understanding Facade Design Pattern

Profile image of Atakan Demircioğlu
By Atakan Demircioğlu
Fullstack Developer

Understanding Facade Design Pattern image 1

Here are my notes about Facade Design Pattern.

What is Facade Design Pattern?

It is basically a structural design pattern that provides a simplified Interface to a set of complex classes.

Often needed when there is a large number of interdependent classes or because parts of the code are unavailable.

In other words, we can say it is a camouflage to cover the all complexities of the complex system and provides a simplified wrapper to hide the details of implementations.

The Advantages of Facade Design Pattern

  • Decouple the complex system logic from the clients
  • Promotes the principle of loose coupling
  • Due to the low degree of interdependence of the individual components, changes (modifications, maintenance) are convenient and possible at any team
  • Software becomes more flexible and easily expandable

The Dis-Advantages of Facade Design Pattern

  • A high degree of dependence on the facade interface
  • Complex implementations especially with existing code
  • An extra level of abstraction gets added because of Facade.

Understanding Facade Design Pattern image 2

Exercise

In this example, we are hiding the complexity of drawing something behind the ShapeMaker class.

We are passing Rectangle, Circle, and Square from outside the class because I don’t want to create a dependency inside ShapeMaker. But it is a different topic.

For this example, it is ok to create new instances inside the ShapeMaker function.

References