Facade Design Pattern is a Structural Design Pattern used to provide a unified interface to a complex system. It is same as Facade in building architecture, a Facade is an object that serves as a front-facing interface masking a more complex underlying system. A Facade Design Pattern in C++ can:

  • Improve the readability & usability of a software library by masking interaction with more complex components by providing a single simplified API.
  • Provide a context-specific interface to more generic functionality.
  • Serve as a launching point for a broader refactor of monolithic or tightly-coupled systems in favour of more loosely-coupled code. Frankly speaking, even I don’t understand this point. I have just copied this from Wikipedia.

/!: This article has been originally published on my blog. If you are interested in receiving my latest articles, please sign up to my newsletter.

Before we move forward, Let me correct the spelling of Facade i.e. “Façade” & it pronounces as “fa;sa;d”. A hook or tail added under the letters C called a cedilla used in most of the European languages to indicate a change of pronunciation for that particular letter. We will not go into details of it, otherwise, we would be out of topic.

By the way, If you haven’t check out my other articles on Structural Design Patterns, then here is the list:

  1. Adapter
  2. Bridge
  3. Composite
  4. Decorator
  5. Facade
  6. Flyweight
  7. Proxy

The code snippets you see throughout this series of articles are simplified not sophisticated. So you often see me not using keywords like overridefinalpublic(while inheritance) just to make code compact & consumable(most of the time) in single standard screen size. I also prefer struct instead of class just to save line by not writing “public:” sometimes and also miss virtual destructor, constructor, copy constructor, prefix std::, deleting dynamic memory, intentionally. I also consider myself a pragmatic person who wants to convey an idea in the simplest way possible rather than the standard way or using Jargons.

Note:

  • If you stumbled here directly, then I would suggest you go through What is design pattern? first, even if it is trivial. I believe it will encourage you to explore more on this topic.
  • All of this code you encounter in this series of articles are compiled using C++20(though I have used Modern C++ features up to C++17 in most cases). So if you don’t have access to the latest compiler you can use https://wandbox.org/ which has preinstalled boost library as well.

#coding #programming #software-development #cpp #design-patterns #c++

Facade Design Pattern in Modern C++
1.70 GEEK