4

So requirement is to create a generic interface for multi-step wizard/single-step wizard. Since each wizard might not have all the buttons (single-step wizard has only Cancel and Submit, a multi-step first screen has Cancel, Next and so on).

Should I create a separate interface for each button

interface CancelButton 
{
   void onCancelClick();
}

interface NextButton 
{
   void onNextClick();
}

and so on? And each wizard implement only the ones they require?

Is there any better design pattern for this use case?

Thanks.

Massimiliano
  • 16,770
  • 10
  • 69
  • 112
Android_enthusiast
  • 863
  • 5
  • 22
  • 41
  • Maybe [this](http://msdn.microsoft.com/en-us/library/fs0za4w6(v=vs.100).aspx) can give you some ideas. – Jordão Aug 23 '12 at 18:46
  • You could have a Button interface exposing an onClick method. NextButton, Cancel Button and SubmitButton implement the onClick method to define button specific behavior. You can have a single Wizard class that has a List – Chetan Kinger Aug 23 '12 at 19:49
  • Wizard should have a method called onClick that is passed the Button that was clicked. This method checks if the clicked button is present in the list and delegates to the onClick method of the button that was clicked. – Chetan Kinger Aug 23 '12 at 19:55

1 Answers1

1

It seems like you just need a simple class hierarchy. You'd have some base abstract WizardPage class and subclasses for each essential wizard page case, like WizardWelcomePage, WizardLastPage, WizardIntermediatePage. A wizard is then defined as a collection of wizard pages and each page knows which buttons it should show. Not a particular design pattern, simple OOP.

One other variation of this idea, making things more flexible would be to make the base WizardPage to accept a collection of WizardButton instances in its constructor (and WizardCancelButton, WizardAcceptButton, WizardNextButton would be the subclasses). This will allow you to have separate hierarchies (variations) for wizard pages and wizard buttons. I think this can be considered as a Bridge pattern then. Each of the button subclasses would ask for another interface in their constructor so that when they are clicked they can send this information to the WizardEngine which will make the appropriate action: move to the next page, cancel or accept. You will probably also need another chain of events going from each WizardPage to indicate when the content became valid or invalid, so that the appropriate buttons can be enabled\disabled by the WizardEngine.

Massimiliano
  • 16,770
  • 10
  • 69
  • 112