0
0
LLDsystem_design~12 mins

Factory Method pattern in LLD - Architecture Diagram

Choose your learning style9 modes available
System Overview - Factory Method pattern

The Factory Method pattern helps create objects without specifying the exact class of object that will be created. It defines an interface for creating an object but lets subclasses decide which class to instantiate. This allows flexible and scalable object creation in software design.

Architecture Diagram
  +-------------+       +----------------+       +----------------+
  |   Client    | ----> | Creator (Factory) | ----> | ConcreteCreator |
  +-------------+       +----------------+       +----------------+
                                |                          |
                                | createProduct()          | createProduct()
                                v                          v
                        +----------------+          +----------------+
                        | Product (Interface) | <---- | ConcreteProduct |
                        +----------------+          +----------------+
Components
Client
component
Requests products from the factory without knowing the concrete classes.
Creator (Factory)
factory
Defines the factory method to create products and may provide default implementation.
ConcreteCreator
factory
Overrides the factory method to instantiate specific concrete products.
Product (Interface)
interface
Defines the interface for products created by the factory.
ConcreteProduct
product
Implements the product interface and represents the actual product created.
Request Flow - 4 Hops
ClientCreator (Factory)
Creator (Factory)ConcreteCreator
ConcreteCreatorConcreteProduct
ConcreteProductClient
Failure Scenario
Component Fails:ConcreteCreator
Impact:If the concrete creator fails, the client cannot get the specific product instance, causing creation failure.
Mitigation:Use default implementations in Creator or fallback factories to provide alternative products or error handling.
Architecture Quiz - 3 Questions
Test your understanding
Which component decides which concrete product to instantiate?
AConcreteCreator
BClient
CProduct Interface
DCreator (Factory)
Design Principle
The Factory Method pattern separates object creation from usage, enabling flexible and scalable designs by letting subclasses decide which concrete products to instantiate.