Design Patterns — Facade

Patroclos Lemoniatis
2 min readMar 7, 2021

--

image from pixabay by theglassdesk

Facade as a Structural Pattern, is used mainly to provide a single point of entry to a complex subsystem. In object oriented programming, is a single object which is used to orchestrate and call other objects to perform various tasks.

In summary a facade is able to …

  • Improve the readability and usability
  • Provide a simpler generic interface to a more complex functionality
  • Hide the implementation details
  • Restrict access to subsystem

Case Study

Consider an enterprise application used to create,manage and bill customers. A new requirement came up, where a user from a new User Interface — an Android app, needs to create Customer Contracts. There is no need to expose the whole functionality of the system, only a a single point of entry where it will receive an input with all the customer details, and return an output. What happens in betwwen the process of adding customer to registry, add to billing and creating the new contract, is not exposed to the Android app which is going to be developed.

In addition, event logs need to be recorded for auditing and user permissions need to enforced.

Implementation

1.Create Interface Facade

2.Create concreate class ProcessFacade implementing Interface Facade. Add the process logic of creating a new Customer contract. Plus adding the loging event and user permissions validation.

3.Create subsystem classes, CustomerService,ContractService and BillingService

When we run the Facade we get the following …

Verifying user…Creating contract Customer…Creating Contract…Adding contract to Billing…Logging contract creation…

In conclusion, when a user enters all the required details from the Android app, and clicks a button for creating a contract, all the internal processes (loging,user permission validation, create contract) are ran in favor of the app from the facade.

Facade design pattern in general

  • Provides an interface as a single point of entry, minimizing thri-party clients interaction with the subsystem
  • Loose Coupling, minimize dependencies
  • Easy to implement
  • Business Logic consolidation

--

--

Patroclos Lemoniatis
Patroclos Lemoniatis

No responses yet