aspose file tools
The moose likes OO, Patterns, UML and Refactoring and the fly likes State pattern - Wizard implementation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of The Software Craftsman this week in the Agile forum!
JavaRanch » Java Forums » Engineering » OO, Patterns, UML and Refactoring
Bookmark "State pattern - Wizard implementation" Watch "State pattern - Wizard implementation" New topic

State pattern - Wizard implementation

Omkar Shetkar
Ranch Hand

Joined: Jun 22, 2006
Posts: 55


I am refactoring a legacy code to implement wizard. I thought of refactoring using state pattern.
A wizard may consist of related/unrelated steps. Each step can be considered as a state. A controller/context to control the flow of the wizard.

My problem is input of flow/sequence of wizard steps. This flow can be handled

1. in controller with lot of if...else statements. OR
2. each state can tell the controller which should be the next state.

Problem with the first solution it will complicate and maintenance will become difficult.
If I go with the second solution, the next state decision will get tightly coupled with the state. If in future I want to reuse the state, I can't resue it since it is tightly coupled with the next state decision behavior.

[moderator corrected the title]

Are there any other ways of inputting/controlling the STEP flow?

Thanks & Regards,
Omkar V S
It is sorta covered in the JavaRanch Style Guide.
subject: State pattern - Wizard implementation