This design pattern allows to maintain single copy. At various places, I required that only one instance should exist. This design patterns helped to ensure this requirement.
This design pattern helps to provide clean interface for a subsystem.
For example, component A needs to handle user login, ensures delivery of commands to firewall, handles unreachable firewall. So, component A has multiple sub-subsystem (Driver, HTTP Handler, Command management). These subsystems interact with each other using Facade design pattern. Facade design pattern provides clean and extensible interface between these subsystems. For example, ICommand, IDriver, etc.
This design pattern helps to segregate changing part and common part of algorithm.
Component A needs to interact with third-party firewalls. In reality, these third-party firewall exposes non-standard APIs. Provisioner needs to be generic enough to execute common flow using single set of code. Creation of XML request depends on firewall. For example, Palo-alto and Checkpoint XML requests have different formats. To generate request HTTP body, driver uses Template design pattern.
Traditional state machine uses conditional if. This approach has disadvantages.
>> It is difficult to add new state.
>> It is less readable and maintainable.
>> application logic mixes with state handling and it hinders caller to focus on business logic.
This design pattern solves above problems.
Producer-Consumer
Curl handing subsystem processes commands transparently. This means that curl module is unaware of the request format. This approach helps decoupling between curl module and Driver and also helps to keep curl module generic and driver agonstic. However, command response from firewall needs to be handled by Driver since it understands the XML. So, here, curl module is producer and Driver is consumer. Moreover, to harness best performance, Driver should process response asynchronously.
This design pattern meets above requirement.
I used this design pattern at multiple places whenever event handling mechanism is needed.
Abstract Factory
This design pattern helps to create instance of several families of classes.
Based on firewall type, driver object configures itself. Subsystem A which uses driver is not aware of these difference. For this, I used this design pattern.
Driver creates command object and then passes this command to curl handler. Curl handler processes command and inform driver to handle response. This is command design pattern example.