Home » Façade Design Pattern in Python

Façade Design Pattern in Python

by Online Tutorials Library

Façade Design Pattern

Façade is a structural design pattern which provides the simpler interface to a library or complex set of classes. The word Façade is simply referred to an outer lying interface of complex patterns that contains several sub-systems. It is a very important part defined by the Gangs of Four design patterns. In the simple word, it defines the higher level interface that any subsystem can use.

The main façade class keeps track which subsystem is responsible for a request.

This design pattern helps in communicating with the subsystem easily to the client.

Façade Design Pattern

Problem without Façade Design Pattern

Suppose we have written the code to work with a large set of the objects which belong to the sophisticated framework or library. So here we need to take care about the all dependencies, initialize all of those objects, execute methods in the correct order, and so on.

For example – Imagine you call a pizza shop to place an order. The executive takes and your pizza will be prepared by the chef. Then, it will deliver to you. So there are several subtasks related with each other. We need to create a system that automates the whole task without the disturbance of us.

Solution using Façade Method

To solve the problem, we require a façade method. It will help us to hide the complexity of the subsystem. Here an operator (executive) is your façade to all services and departments of the shop.

Your voice works as the interface to the ordering system, payments, and gateways and delivery service.

Let’s understand the following example.

Example –

Advantages of Façade Method

There are several advantages of using façade method; we describe few important advantages as follows.

  • Façade method helps us to isolate our code from the complexity of a subsystem.
  • It provides the loose coupling between the client and the subsystems.
  • It makes the testing process easy since it contains convenient methods for common testing task.

Disadvantages of Façade Method

Below are the few disadvantages of façade method.

  • Applying the façade method is expensing. It is not cheap to establish façade method for system reliability.
  • Façade method violates can violates the construction of the façade layer.
  • Façade object can become a supreme object coupled to all classes of an app.
  • If we make the change in the subsequent method, that may bring change in the Façade method which is not acceptable.

Applicability

Let’s understand the applicability of the façade method.

  • The most essential application of façade method is that, it provides the simple interface to the complex subclass.
  • Façade method is quite useful when we want to provide a unique structure to a sub-system by dividing them into layers. It also provides the loose coupling between the client and the subsystem.

You may also like