The problem I'm solving consists of many interdependent steps. The order in which these steps are executed must be preserved. Not all steps are obligatory. So, to be more clear, I want something like this:
if (STEP_ONE_ENABLED){
StepOneClass.Execute();
}
if (STEP_TWO_ENABLED){
StepTwoClass.Execute();
}
....
if (STEP_N_ENABLED){
StepNClass.Execute();
}
StepOneClass, StepTwoClass ... StepNClass are all derived from the abstract Step class. I was thinking to add them all in a list if they're enabled, and then execute each item in the list. However I don't think that this is a good way to make sure that the execution order is maintained.
I wanted to use the Chain of Responsibility design pattern, where each class will call it's successor after it's done executing its own logic. But still, how'd I determine the successors? Should I always iterate all steps and choose the first one that's enabled? Any suggestion and idea on a good design would be appreciated.
I'm using C# ASP.NET.
Aucun commentaire:
Enregistrer un commentaire