07 Dec 2023
Intermediate
| Feature | Abstract Factory | Factory Method |
|---|---|---|
| Intent | Create families of related or dependent objects without specifying their concrete classes. | Define an interface for creating an object, leaving the choice of its type to the subclasses. |
| Scope | Creates families of related objects. | Creates a single object, allowing subclasses to alter the type of objects created. |
| Number of Classes Involved | Involves multiple classes: Abstract Factory, Concrete Factory, Abstract Product, Concrete Product. | Typically involves two classes: Creator (Abstract Creator) and Concrete Creator. |
| Creation Mechanism | Creates multiple related objects, often organized into families or themes. | Creates a single object, but the specific type is determined by subclasses. |
| Participants | Abstract Factory, Concrete Factory, Abstract Product, Concrete Product. | Creator (Abstract Creator), Concrete Creator, Product, Concrete Product. |
| Client Interaction | Clients use the Abstract Factory interface to create families of objects. | Clients use the Factory Method to create a single object without specifying its class. |