Abstract Factory Structure and Participants
The Abstract Factory pattern involves four key participants that work together to create families of related objects while maintaining loose coupling.
Structural Components
Participant Roles
AbstractFactory: Declares an interface with creation methods for each abstract product type. This interface defines the contract that all concrete factories must fulfill. Each method typically returns an abstract product type, not a concrete implementation.
ConcreteFactory: Implements the abstract factory interface to create concrete product objects. Each concrete factory corresponds to one product family variant. For example, WindowsFactory creates Windows-specific UI components, while MacFactory creates Mac-specific components.
AbstractProduct: Declares an interface for a type of product object. Each distinct product type in the family has its own abstract product interface (like Button and TextField in a UI toolkit).
ConcreteProduct: Implements the abstract product interface for a specific variant. Products created by the same concrete factory are designed to work together. For example, WindowsButton and WindowsTextField share the same visual style.
Key Relationships
The inheritance relationship (▲) connects concrete factories to the abstract factory, and concrete products to their abstract product interfaces. The client has a composition relationship (◆) with the abstract factory, meaning it holds a reference to a factory instance but doesn't know which concrete factory it is.
new ConcreteProduct(). All object creation goes through the factory, which is the entire point of the pattern.