Reputation: 903
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.
Upvotes: 4
Views: 1732
Reputation: 16980
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
.
Upvotes: 1