Creational
5 pagesHow objects get made: factories, builders, prototypes and the one-instance rule.
Creational — how objects get made — intent and sightings
| Pattern | Intent | Real-world JS sighting | File |
|---|---|---|---|
| Abstract Factory | One factory object yields a whole family of compatible products | Knex dialect clients; providers[name] kit (charge + refund + verify) | creational/abstract-factory.js |
| Builder | Assemble a complex object step by step, then build() | Knex/Kysely query builders; Zod schemas; superagent chains | creational/builder.js |
| Factory Method | Defer the new to a hook so a subclass/key picks the class | document.createElement, http.createServer, React.createElement | creational/factory-method.js |
| Prototype | Create new objects by cloning a configured instance | Object.create, structuredClone, spread copies in reducers | creational/prototype.js |
| Singleton | Exactly one instance, globally reachable | Node module cache (module.exports = new Logger()), Redux store, process | creational/singleton.js |
- Abstract Factory2 sections
- Builder2 sections
- Factory Method2 sections
- Prototype2 sections
- Singleton2 sections