Creational patterns
Factory Method
Subclasses decide which concrete object gets created; callers depend only on a shared interface.
Article
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.
Related articles
- 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.
- Flyweight – how to fit 60,000 stadium seats in memory
Flyweight separates the state shared by many objects from the state unique to each one, and shares the former. A stadium seat map example from a ticket booking system in C#, TypeScript, Java, Go and…
Challenges
- Notification factory easy
Around the topic
- Factory Method Pattern – Design Patterns (ep 4) video · youtube · Christopher Okhravi
- Factory Method article · web · Refactoring.Guru
- Design Patterns: Elements of Reusable Object-Oriented Software book · openlibrary · Erich Gamma, John Vlissides, Richard Helm, Ralph Johnson
- Head First design patterns book · openlibrary · Eric Freeman, Elisabeth Freeman, Kathy Sierra, Bert Bates
- Design Patterns in Dynamic Languages | Code Walks 016 video · youtube · Christopher Okhravi
- Metoda wytwórcza / Factory Method article · web · Refactoring.Guru