OOD & LLD Reference/Design Patterns (Interview Core)

Creational Patterns

Factory Method, Abstract Factory, Builder, and Singleton — when each is justified, why Singleton is controversial, and how dependency injection replaces most Singleton use cases.

3/5Overview: 25m

Creational patterns in LLD context

Creational patterns answer: who constructs this object, and how do we hide the complexity? In interviews, you rarely name the pattern — you reach for it when constructors explode or construction logic scatters across callers.

PatternUse whenSkip when
Factory MethodSubclass decides which product to create (DocumentParser.create())One product type, trivial new
Abstract FactoryFamilies of related products (UI theme: Button + Checkbox)Single product, no family constraint
BuilderMany optional fields, stepwise validation (HttpRequest, PizzaOrder)≤ 4 required fields
SingletonTruly one instance in the process (config loader)Testability, DI, or "global state" smell

Factory vs Builder

Factory encapsulates which concrete type to instantiate. Builder encapsulates how to assemble a complex immutable object. They compose: HttpClient client = HttpClientBuilder.create().timeout(30).build(); — Builder constructs, Factory may select the builder implementation.

Singleton controversy

Singleton is a global variable with a dress code. Problems: hidden dependencies, hard to mock, lifecycle tied to class loader. Prefer dependency injection of a single shared instance (Spring @Bean, manual constructor injection). If you must use Singleton in Java, enum singleton (Effective Java Item 3) is the safest variant.

Object pool awareness

Object Pool (less common in LLD) reuses expensive instances (DB connections). Mention only if interviewer brings up connection limits — otherwise Factory + DI covers 95% of creational needs in loops.

Senior-level signal

Say: "I'd inject a VehicleFactory so ParkingLot doesn't know about Car vs Truck — that keeps OCP intact and makes tests pass a MockVehicleFactory." For Builder, walk through why telescoping constructors fail: parameter order ambiguity and invalid partial states.

Where this goes next

Structural Patterns covers wrapping and layering — Adapter, Decorator, Facade, and Proxy — the patterns you use once objects exist and need to interact.

Further Reading

Practice Tasks (Optional)

Design or implement locally in any language — no autograding. Focus on class structure, extensibility, and being able to explain trade-offs out loud.

  • Design a Builder for a complex object

    Pick HttpRequest, PizzaOrder, or DatabaseConfig. Write the Builder API (method chaining) on paper with 5+ optional fields. Explain why constructor telescoping fails here.

    20m