lundi 10 juin 2019

Why is factory method not necessary when instantiation takes place in an operation that subclasses can easily override"?

From Design Patterns by Gamma et al,

Factory Method makes a design more customizable and only a little more complicated. Other design patterns require new classes, whereas Factory Method only requires a new operation. People often use Factory Method as the standard way to create objects, but it isn't necessary when the class that's instantiated never changes or when instantiation takes place in an operation that subclasses can easily override, such as an initialization operation.

  1. "Other design patterns" include abstract factory, builder and prototype. Isn't it that prototype does not require new classes either, just like factory method? Or do I misunderstand what "require new classes" means?

  2. What does it mean by "when instantiation takes place in an operation that subclasses can easily override, such as an initialization operation"? Why is factory method not necessary in this case?

Thanks.

Aucun commentaire:

Enregistrer un commentaire