Answer the question
In order to leave comments, you need to log in
How to implement elegant code flow?
I am writing a system for the customer, in the main part of which is the execution of a certain scenario, depending on the parameters.
There are only two parameters (I give a simplified code):
string paramA;
string paramB;
Worker w = new Worker();
switch (paramA)
{
case "in":
switch (param2)
{
case "one":
w.do1();
w.do2();
w.do3();
break;
case "two":
w.do2();
w.do4();
break;
case "three":
w.do1();
w.do5();
w.do2();
break;
case "four":
break;
case "five":
break;
}
break;
case "out":
break;
default:
break;
}
in-one => { w.do1(); w.do2(); w.do3() }
in-two => { w.do2(); w.do4(); }
Answer the question
In order to leave comments, you need to log in
Create a list of all tasks, and a strategy for execution.
var Actions = new Dictionary<String, Action> {
{"foo", w.foo },
{"bar", w.bar }
};
var Strategies = new Dictionary<String, List<String>>(){
{"in one", new List<String> { "foo", "bar" } }
};
// run
var actions = Strategies["in one"];
actions.ForEach((action)=> Actions[action]());
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question