- What to look for:
- Same set of objects belonging to different groups
- Intent: creating families of related objects without specifying concrete classes
- Grouped creation of set of related objects without knowing their concrete classes (e.g., UI-theme from dark to light)
- Basically like creating lots of abstract products that are somehow related to each other?
- Use cases
- Cross-platform/theming UI-toolkit
- Connecting to several databases
- Configuration and environmental set-up
- Components
- Abstract Factory
- Declares the interface for the creation of the products in the family
- Concrete factory
- Implements the factory methods in the
Abstract Factory
- Abstract product
- Defines an interface for a type of product object. There will be one
Abstract product
for each type of product in the family
- Concrete product
- Implements an
Abstract Product
interface
- Client
- Oblivious to concrete factories and concrete factories and concrete products .It just knows abouts the abstract factories (for which the all have the same products with the same methods (polymorphism))
- Flow
- Client chooses a concrete factory (e.g., it instantiates DarkThem())
- Client request products from the factory (e.g., factory.create_button())
- Factory creates concrete product
- Client uses abstract product
- Code sample
EXTRA
- Staging is one the three phases of code development (dev, staging, production). It is an scenario that very closely resembles production without being exactly it