api: YAML JSON TOON Database version: 1.0.0 format: json dataset: id: 9 slug: creational-patterns title: Creational Design Patterns description: "Patterns for object creation: Singleton, Factory Method, Abstract Factory, Builder, and Prototype with intents and use cases." summary: "Creational design patterns that control how objects are created: Singleton, Factory Method, Abstract Factory, Builder and Prototype, plus Object Pool, Lazy Initialization and Dependency Injection, each with intent and when to use it." use_when[2]: You need to decouple code from the concrete classes it instantiates.,You are choosing among factory-style patterns. caveats[2]: Singleton is often overused and acts as hidden global state; dependency injection is usually a better alternative.,"Dependency injection is a technique rather than a Gang of Four pattern, listed here because it addresses the same problem." related[4]: structural-patterns,behavioral-design-patterns,solid-principles,architectural-design-patterns category: Design Patterns category_slug: design-patterns tags: "design patterns,oop,software engineering" view_count: 0 created_at: 1777673262 updated_at: 1777673262 entry_count: 8 fields[3]{section,field,type,example}: patterns,name,string,Singleton patterns,intent,string,Ensure a class has only one instance patterns,when_to_use,string,"Shared resource access, global state" data: patterns[8]{name,intent,when_to_use}: Singleton,Ensure a class has only one instance,"Shared resource access, global state" Factory Method,Create objects without specifying exact class,Decoupling object creation from usage Abstract Factory,Create families of related objects,Multiple product variants Builder,Construct complex objects step by step,Many configuration options Prototype,Create new objects by copying existing ones,Object creation is costly Object Pool,Reuse a set of expensive-to-create objects instead of creating and destroying them on demand,"Database connections, threads and other costly resources" Lazy Initialization,Delay creating an object or computing a value until it is first needed,Expensive objects that may never be used Dependency Injection,Supply an object's dependencies from outside instead of letting it construct them,"Testing, configuration and swapping implementations without changing callers"