Explain the difference between the main Creational patterns (when to pick which).

Topic: design-patterns, Creational Patterns. Level: Intermediate.

Answer

- **Singleton**: exactly one shared instance. - **Factory Method**: pick one concrete product behind an interface (subclass/method decides). - **Abstract Factory**: create a whole **family** of compatible products. - **Builder**: assemble a complex object step-by-step (many optional fields, immutability). - **Prototype**: clone an existing configured instance (expensive creation). Rule: many params → Builder; one-of-many types → Factory Method; families → Abstract Factory; expensive-to-create → Prototype; single global instance → Singleton. ```text Need -> Pattern one shared instance -> Singleton choose a concrete type via interface -> Factory Method a family of related objects -> Abstract Factory complex object, many optional fields -> Builder copy a costly-to-build instance -> Prototype ```