Skip to main content


Showing posts with the label Design-Patterns

The Facade pattern

Facade design pattern is a structural design pattern and it's used widely. The aim of this design pattern is to provide a simple interface to the client for a complex underlying system. So, facade means face of the building. This design pattern hides all complexities of the system and just displays a simple face. Very common example could be URL interface of a browser, which hides all complexities behind and only accepts a URL which user intends to browse. Another common example could be withdrawal / deposit of money from banking system via ATM. To withdraw money we need following steps to achieve successfully: 1. Validate card / account number 2. Validate pin 3. In case of withdrawal check account balance and allow / disallow withdrawal 4. Follow steps 1 & 2 for account deposit (Steps 3 not needed). 5. Finally show the balance. Code Example:  <Code> File: WelcomeBank.h #pragma once #include < fmt/format.h > class WelcomeBank{     public :         // ctor...    

The Visitor pattern

What is visitor pattern? 1.      It encapsulates an operation executed on an object hierarchy in an object. That says, it allows to add   methods to classes of different types without much altering to those classes. 2.        Enables to define new operations without changing the object hierarchy. Use-Case: a. Operations shall be performed on object hierarchy b. The operations change frequently but object hierarchy is stable. Basic UML Class Diagram:         Visitor: ·   Defines the visit operation on the object structure     Tax Visitor: ·   Implements the visit operation for each type of object     Visitable: ·   Defines the accept operation which takes visitor as an argument      Visitable Element(s):                    ·   Implements accept operations        The Visitor pattern has two types of hierarchies . The object hierarchy (Visitable elements) and the operation hierarchy (TaxVisitor). The object hierarchy is pretty stable, but operation hierarchy may