mardi 30 décembre 2014

Template design pattern for operations with parameters

Template design pattern lets you design an algorithm which can be customized by overriding some template methods.



class Algorithm {
protected void init();
protected void prepareCup();
protected TeaBag prepareTeaBag();
protected void boilWater();
protected void putWaterIntoCup();
}


prepareTeaBag() can return arbitrary tea bags to make custom tea.


But what if I have an algorithm that would require some parameters for operations, for example name of the tea bag, and some other properties that are being changed into each of the operation. I can save those properties into class as a class members but that way I can't call it from different threads. I would need to pass some Context class that would change depending on operation in order to allow multi threading access, or something what are your thoughts on this?


Aucun commentaire:

Enregistrer un commentaire