My suggestion is to create an interface as a class:
public interface IStepDecisionMaker { StepInfo DefineNextPreviousStep(object data); } public class StepInfo { public int NextStepId {get;set;} public int PreviousStepId {get;set;} public object Values {get;set;} }
Now you can add a table to the database or XML, where you install all the available steps and assign a specific class to each step that implements the IStepDecisionMaker interface
In your action, you can collect step data and using the IoC system or CreateInstance reflection, you can create an instance of a specific class, call DefineNextPreviousStep, passing in the data you need to check, and the method can return a class that tells you what the next or previous steps are
This way you can achieve several things.
- your action will have only a few lines of code
- logic is not a ton if then, but inside each class
- You can change some conditions directly in a particular class of a particular step without touching another part of the code.
IMHO
source share