vendredi 19 mai 2017

Using Template Method and Strategy together

Gang of Four sums up the difference between Template Method and Strategy as follows:

Template methods use inheritance to vary part of an algorithm. Strategies use delegation to vary the entire algorithm.

What are the scenarios where combining two designs would be justified and how their relationship would look like?

Trivial example would involve delegating to Strategy inside hook methods of a Template Method, however, I cannot think of a good justification for such design. Additionally, instead of delegating to subclass one might delegate to Strategy directly. But then, without inheritance, we cannot talk about Template Method at all.

Aucun commentaire:

Enregistrer un commentaire