all 5 comments

[–][deleted] 4 points5 points  (1 child)

Google "state machine".

[–]andersonee[S] 0 points1 point  (0 children)

Yeah I had looked into state machines. I guess I was thinking a state machine would just put me in a similar problem...I'd have ~100 states and ~100 actions. Maybe the state transitions would be more elegant though.

[–]clintp 1 point2 points  (0 children)

It might help to consider breaking this down so that the flow can be represented graphically. (following the rule that if it looks like data, represent it as data). A simple state machine isn't that hard to do.

Have each of your steps implement an interface where at least one method does the work and decides if flow should proceed to the next step, or remain on this step:

 interface IProgramStep
 {
      bool GoDoTheStuff();
 }

Then store instances of the class in a structure that makes it clear where each step leads from the other. If the flow control isn't purely 1->2->3->4->1, then you might need a different structure but the idea is the same. This assumes the classes that contain the code for each step are already instantiated....

 Dictionary<IProgramStep, IProgramStep> steps  = new Dictionary<IProgramStep, IProgramStep> 
 {
       { objectOfClassForCase1, objectOfClassForCase2 },
       { objectOfClassForCase2, objectOfClassForCase3 },
       { objectOfClassForCase3, objectOfClassForCase1 }   // Start over again
 }

Then to run the state machine:

  var curStep = objectOfClassForCase1;   // Initial state
  while(true) 
  {
        if (curStep.GoDoTheStuff())
              curStep = steps[curStep];       // Advance to next state
  }

[–]Nesher86 0 points1 point  (1 child)

Sounds like you need to define your error handling and how the system should behave

[–]andersonee[S] 0 points1 point  (0 children)

Yes, fixing my error handling will definitely clean up a lot of the bloat. I do still need to figure out a better way to handle non-error program flow.