Factory Design Pattern is widely used by developers fluent with OOPS. The popularity stems from the flexibility and maintainability that the design pattern offers in dynamic business ecosystems. Visualise the design as a factory (superclass or common interface) that summons individual units (concrete class) based on the invoked business scenario. This invocation happens through a lobby (factory method), which decides the individual unit (concrete class) to be summoned based on input data. The person in the lobby doesn’t know how the factory operates or what the scale is. It’s a simple, lean and clean solution design.
One of the most commonly used use cases is Sales Order creation, where the user provides item details, quantity and his address. The factory method takes care of all the backend processing by creating relevant orders, delivery dates (in case of multiple items), etc., without having the user bother about the nitty gritty of the sales order cycle. Payment for the order is another excellent use case. Once the user reaches the payment page,e providing personal choice, the factory method loads the relevant gateway and allows the user to complete the transaction.
By decoupling logic, the code becomes flexible. From a developer’s perspective, it is a huge win. The extensibility of the code becomes easier and manageable. The changes are localised, which simplifies the testing process in build and during defect fixes. Multiple developers can work in tandem without affecting the overall solution. Besides, the organised structure provides benefits of modularisation, like ease of debugging and maintainability as well.
From a project lifecycle perspective, besides ease of development and maintainability, the Factory Design Pattern ensures the solution is agile (able to handle changes of logic) and scalable (able to handle changes of scope). This effectively leads to lower technical debt and less maintenance costs as well.
~S
Leave a comment