MΓ³dulo 23 Β· Design Patterns (All 23 GoF) β LecciΓ³n 3 de 23 Β· ~6 min
Abstract Factory
Abstract Factory: build FAMILIES of related objects
Problem: you need a matched set of objects that must be used together β mixing them would be a bug.
PawWalk scenario: for payments you need a charger AND a refunder that belong to the same provider. Stripe's charger with PayPal's refunder is nonsense. An abstract factory hands you a coherent pair.
In Ruby the 'factory' is often just a method returning a small object (a Struct or OpenStruct) that exposes the related methods.