Design Pattern for Skipping Steps in a Wizard
Posted
by
Eric J.
on Programmers
See other posts from Programmers
or by Eric J.
Published on 2012-07-11T03:03:02Z
Indexed on
2012/07/11
3:22 UTC
Read the original article
Hit count: 252
design
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.
}
}
© Programmers or respective owner