Creational patterns
Abstract Factory
Produces families of related objects that are guaranteed to work together.
Article
Abstract Factory – whole families of objects that fit together
Abstract Factory creates a complete set of related objects from one family and makes sure nobody mixes parts from different sets. An example with two payment provider integrations.
Related articles
- Singleton – one instance, and the reasons to hand it to a DI container
Singleton guarantees that a class has exactly one instance available to the whole application. We show thread-safe implementations in five languages and explain why today it is usually better to…
- Prototype – a new object as a copy of a ready-made template
Prototype creates objects by cloning a configured instance instead of building them from scratch. We explain the difference between shallow and deep copies using exam templates as an example.
- Factory Method – let the subclass decide what gets created
Factory Method separates the algorithm that uses an object from the decision about which exact object is created. A ticket booking example in C#, TypeScript, Java, Go and Python.
- Builder – complex objects step by step
Builder collects an object's parameters in readable steps and hands over a finished, valid product only in build(). A catering order example in C#, TypeScript, Java, Go and Python.
- Bridge – two axes of change without a class explosion
Bridge separates the abstraction (what we do) from the implementation (how we do it), so both hierarchies can evolve independently. An example of notifications and delivery channels in C#,…
Around the topic
- Abstract Factory article · web · Refactoring.Guru
- Abstract Factory Pattern – Design Patterns (ep 5) video · youtube · Christopher Okhravi
- Design Patterns: Elements of Reusable Object-Oriented Software book · openlibrary · Erich Gamma, John Vlissides, Richard Helm, Ralph Johnson
- iluwatar/java-design-patterns repo · github · iluwatar
- Fabryka abstrakcyjna / Abstract Factory article · web · Refactoring.Guru