4

I have a 45 step wizard UI (complex domain - insurance). It's implemented in ASP.NET MVC 3. The problem is my action methods have a lot of code to determine what the next step is, depending on user, already collected data, weather forecast ... And even worse, similar code is repeated for the back button functionality. Is there a pattern I can use to abstract this logic? I'm hoping for a way to define the forward steps and get the backward step automatically.

  • I would suggest you to use the MVVM framework like knockoutjs where you can bind model with behavour and appearance combining declarative and imperative approaches. – Kath Nov 22 '12 at 23:28
  • Couldn't agree with @Kate more. You can spend countless hours, days, weeks figuring out the logic to handle this in your code behind, or put it all together in a nice bundle client side. I have found that updating one script file is much easier than bouncing between a ton of functions and controllers. Just my two cents :) – DeeDub Nov 26 '12 at 16:03
  • Do you still need help with this? – MarkG Jan 08 '13 at 07:18
  • You can try to use this: http://webflow.codeplex.com/. This is project that I developed as final thesis and I'm using it in production in one commercial project. – Sławomir Rosiek Jan 09 '13 at 20:37
  • What about this? http://stackoverflow.com/a/6403485/1844389 – Bhushan Firake Jun 05 '13 at 17:57

1 Answers1

0

My suggestion is to create an Interface an a class like:

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;}
}

you can now add a table in a DB or XML where setting all the available steps and per each step assign them a concrete class that implemente the interface IStepDecisionMaker

In you action you can collect the data of the step and with a IoC system or a reflection CreateInstance you can create an instance of the concrete class, call the DefineNextPreviousStep passing the data you need to check and the method can return a class that will tell you what are the next or previous steps

In this way you can achieve several things

  1. your action will have just few lines of code
  2. the logic is not a tons of if then but is inside each class
  3. you can change some conditions directly in the concrete class of a specific step without touch the other part of the code

IMHO

Simone Belia
  • 253
  • 3
  • 10