lundi 15 octobre 2018

Strategy Pattern - Possible to Dynamically Change Strategy?

https://en.wikipedia.org/wiki/Strategy_pattern

In the book 'Design Patterns Elements of Reusable Object-Oriented Software' of Erich Gamma et. al., you can read the following statement/ drawback of the strategy pattern:

And you can't vary the algorithm dynamically.

Book -> book page 317 enter image description here

But why should it be not possible to change the algorithm/ startegy at runtime??

In my context I have a reference to a Startegy object, e.g., ConcreteStrategyA. Therefore, I could exchange/ replace this object at runtime by an object class ConcreteSatrategyB.

Aucun commentaire:

Enregistrer un commentaire