mercredi 5 octobre 2022

How does the prototype pattern solve the abstract factory pattern issue with many product family?

In Design Patterns Elements of Reusable Object-Oriented Software, it states that one of the issues in the Abstract factory pattern is the following:

  1. Supporting new kinds of products is difficult. Extending abstract factories to produce new kinds of Products isn't easy. That's because the AbstractFactory interface fixes the set of products that can be created. Supporting new kinds of products requires extending the factory interface, which involves changing the AbstractFactory class and all of its subclasses. We discuss one solution to this problem in the Implementation section.

And in the implementation section:

If many product families are possible, the concrete factory can be imple- mented using the Prototype (117) pattern. The concrete factory is initialized with a prototypical instance of each product in the family, and it creates a new product by cloning its prototype. The Prototype-based approach eliminates the need for a new concrete factory class for each new product family.

I don't think I got it. How would a prototype implementation which —from my understanding— makes clonable objects which have the very same properties, solve this issue?

Aucun commentaire:

Enregistrer un commentaire