- Design patterns
- Creational patterns
Creational patterns
Patterns for creating objects without tying your code to concrete classes.
5 guides61 min in totalDesign patterns
The guides, in order
Read them top to bottom: each one builds on the ones before. The ones you've read carry a check.
- Factory Method: Let Subclasses Decide Which Object to CreateLearn the Factory Method pattern through a payment reconciliation job that lets each acquirer subclass pick its own settlement file parser.11 min readStart here
- Abstract Factory: Create Families of Objects That Belong TogetherLearn the Abstract Factory pattern through a point-of-sale example, with diagrams, pseudocode, TypeScript, Python and PHP code, and interview questions.12 min read
- Builder Pattern: Assemble Complex Objects Step by StepLearn the Builder pattern: build a complex object through named steps, keep optional parts optional, and validate everything once in build().14 min read
- Prototype Pattern: Create Objects by Cloning a Configured InstanceLearn the Prototype pattern: build new objects by cloning a configured instance, and decide which fields get a deep copy and which stay shared.12 min read
- Singleton: One Shared Instance, and Why You Usually Want DI InsteadLearn how Singleton guarantees one instance with global access, why it is mostly an anti-pattern, and how dependency injection replaces it.12 min read
About this group
- What you'll find
- Factory Method, Abstract Factory, Builder, Prototype and Singleton, the last one with its problems and how to replace it.
- It's for you if…
- your code is full of "new" and conditionals deciding which object to create.
- How each guide works
- Each guide explains the problem the pattern solves, the solution and an analogy, with a structure diagram and its participants. Then come when to apply it, how to implement it step by step, pros and cons, how it relates to other patterns and code in TypeScript, Python and PHP.