0
0
LLDsystem_design~25 mins

When to use which creational pattern in LLD - System Design Exercise

Choose your learning style9 modes available
Design: Creational Design Patterns Usage Guide
Focus on the five main creational patterns: Singleton, Factory Method, Abstract Factory, Builder, Prototype. Exclude structural and behavioral patterns.
Functional Requirements
FR1: Explain when to use common creational design patterns
FR2: Provide clear criteria for choosing each pattern
FR3: Include examples of scenarios for each pattern
FR4: Support understanding for beginners and non-technical learners
Non-Functional Requirements
NFR1: Use simple language without jargon
NFR2: Keep explanations concise and relatable
NFR3: Focus on practical decision-making, not code details
Think Before You Design
Questions to Ask
❓ Question 1
❓ Question 2
❓ Question 3
❓ Question 4
❓ Question 5
❓ Question 6
Key Components
Singleton pattern for single instance control
Factory Method for flexible object creation
Abstract Factory for creating related object families
Builder for complex object construction
Prototype for cloning objects
Design Patterns
Singleton
Factory Method
Abstract Factory
Builder
Prototype
Reference Architecture
  +-------------------+       +-------------------+       +-------------------+
  |   Singleton       |       |   Factory Method   |       |  Abstract Factory  |
  |  (Single Instance)|       | (Create Objects)   |       | (Families of Obj)  |
  +---------+---------+       +---------+---------+       +---------+---------+
            |                           |                           |
            |                           |                           |
            v                           v                           v
  +-------------------+       +-------------------+       +-------------------+
  |    Builder        |       |    Prototype      |       |   Client Code      |
  | (Step-by-step     |       | (Clone Objects)   |       | (Uses Patterns)    |
  |  Construction)    |       +-------------------+       +-------------------+
Components
Singleton
Any OOP language
Ensure only one instance of a class exists and provide a global access point.
Factory Method
Any OOP language
Define an interface for creating an object but let subclasses decide which class to instantiate.
Abstract Factory
Any OOP language
Create families of related or dependent objects without specifying their concrete classes.
Builder
Any OOP language
Separate the construction of a complex object from its representation so the same construction process can create different representations.
Prototype
Any OOP language
Create new objects by copying an existing object, useful when object creation is costly.
Request Flow
1. Client needs an object and identifies the creation problem.
2. If only one instance is needed, use Singleton to get the instance.
3. If object creation varies by subclass, use Factory Method to delegate creation.
4. If a group of related objects is needed, use Abstract Factory to create them together.
5. If object construction is complex, use Builder to build it step-by-step.
6. If cloning existing objects is efficient, use Prototype to copy them.
7. Client uses the created object without worrying about creation details.
Database Schema
Not applicable for this conceptual design.
Scaling Discussion
Bottlenecks
Singleton can become a bottleneck if used in multithreaded environments without proper synchronization.
Factory Method and Abstract Factory can lead to many subclasses, increasing complexity.
Builder pattern may add overhead if object construction is simple.
Prototype requires careful cloning logic to avoid shared mutable state.
Solutions
Use thread-safe Singleton implementations or dependency injection to avoid bottlenecks.
Keep factory hierarchies manageable and use composition to reduce subclass explosion.
Use Builder only when object construction complexity justifies it.
Implement deep cloning carefully and document cloning behavior clearly.
Interview Tips
Time: Spend 10 minutes explaining each pattern briefly, 10 minutes discussing when to use them, and 5 minutes answering questions or giving examples.
Explain the problem each pattern solves in simple terms.
Describe real-life analogies (e.g., Singleton as a single remote control).
Discuss trade-offs and when not to use a pattern.
Show understanding of how patterns help manage object creation complexity.
Mention thread safety and complexity concerns where relevant.