Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DesignPatterns: Which is most appropriate to use for a wizard style user interface?

Tags:

I am implementing a Wizard style user interface. As a user flows through the wizard, clicking next, depending on the choices they have chosen on each screen, the user will have to go through a certain set of wizard screens.

This is being built in ASP.NET MVC. I am wondering what design pattern would be best suited to implement the logic of the sequence of steps that are in the wizard. Again, they have multiple paths through the wizard depending on choices they make.

Could I use a linked list? The "Command Design Pattern"? What do you recommend?

To put it another way: Where/How do you abstract/encapsulate the logic of determining what is the next step in the wizard based on what the user has chosen on a particular step of the wizard?

like image 989
7wp Avatar asked Apr 17 '09 20:04

7wp


2 Answers

The "State" pattern might make sense, if you want to allow the user to navigate forwards and backwards through the wizard.

A workflow pattern might also make sense. Maybe investigate using Windows Workflow foundation.

like image 119
Andy White Avatar answered Oct 12 '22 08:10

Andy White


To put it another way: Where/How do you abstract/encapsulate the logic of determining what is the next step in the wizard based on what the user has chosen on a particular step of the wizard?

One way to do it would be to model Wizard, Step, and Product classes. Maybe something like this?

public class Wizard
{
  public Step forward() {//...}

  public Step backward() {//...}

  public Step current() {//...}

  public Product getProduct() {//...}
}

public class Step
{
  public String name() {//...}

  public void commit(Product product) {//...}

  public void rollback(Product product) {//...}
}

public class Product
{
  //...
}

The purpose of the Wizard is to build a Product (Car, Computer, Vacation, etc).

In this scenario, it's Wizard that decides the next step - perhaps based on the state of the Product that the Wizard is building. Wizard would be acting like a Builder under the control of the UI, which would be the Director and tell Wizard when and in what direction to make a transition. It's up to Wizard to decide what the next step actually is. Multiple branchpoints could be supported, but that implementation would be hidden away inside Wizard.

Step would be be an instance of the Command Pattern with undo/redo capability.

like image 35
Rich Apodaca Avatar answered Oct 12 '22 07:10

Rich Apodaca