HFDP - Abstract Factory

If we need to create objects from families of product we could use the Abstract Factory Pattern, that provides an interface to create families of related objects without specifying their concrete class.

The AbstractFactory defines the interface for all the ConcreteFactory, basically providing an abstract method for each product that has to be created.

The Client is written referring to the AbstractFactory interface that would be set to a ConcreteFactory at runtime.

For instance, our PizzaStore could use an Abstract Factory to make available to the process specific ingredients accordingly to the actual PizzaStore is running.

So, the NYPizzaStore would use the NYIngredientFactory, in this way our call in the client for, say, ingredient.createDough(), would resolve in a call for that specific ingredient factory, that would give us the specific dough for the New York pizza style.

This post was about the third part of chapter four of Head First Design Patterns, by Freeman, Freeman, Sierra, Bates. Get the book for more details.

No comments:

Post a Comment