Design Pattern for Skipping Steps in a Wizard
- by Eric J.
I'm designing a flexible Wizard system that presents a number of screens to complete a task. Some screens may need to be skipped based on answers to prompts on one or more previous screens.
The conditions to skip a given screen need to be editable by a non-technical user via a UI. Multiple conditions need only be combined with and.
I have an initial design in mind, but it feels inelegant. I wonder if there's a better way to approach this class of problem.
Initial Design
UI
where
The first column allows the user to select a question from a previous screen.
The second column allows the user to select an operator applicable to the type of question asked.
The third column allows the user to enter one or more values depending on the selected operator.
Object Model
public enum Operations { ... }
public class Condition
{
int QuestionId { get; set; }
Operations Operation { get; set; }
List<object> Parameters { get; private set; }
}
List<Condition> pageSkipConditions;
Controller Logic
bool allConditionsTrue = pageSkipConditions.Count > 0;
foreach (Condition c in pageSkipConditions)
{
allConditionsTrue &= Evaluate(previousAnswers, c);
}
// ...
private bool Evaluate(List<Answers> previousAnswers, Condition c)
{
switch (c.Operation)
{
case Operations.StartsWith:
// logic for this operation
// etc.
}
}