From time to time I implement functionality which requires asking user questions sequentially.
Questions are conditional, that is the answer defines the set of the following questtiongs.

Sure it is Wizzard UI design pattern, but for now I have no clear understanding how it is implemented from the point of view of software architecture.

Screen/question can be a somewhat complex interface but most fo the time it's just a selection of several options.
Nonetheless after any step some calculations can be required, not only to get additional data but to define the set of questions.

I guess Strategy pattern has to do with this but I feel that the with this pattern the code which builds "execution flow" can become ugly.

Thanks in advance.

  • @Juhana Is there magic button to migrate or I just need to delete the question and then repost on programmers? Mar 29, 2013 at 11:08
  • 1
    You can flag the question and write a comment to the moderators.
    – JJJ
    Mar 29, 2013 at 11:09
  • It is hard to give you a clear answer, because the "right" pattern depends on many factors. That is the reason why I do not consider this as an answer, but just a note: From what you describe I would rather have a look on the State Pattern. Complex dialogs you are talking about may resemble a finite-state machine. Mar 30, 2013 at 13:46

2 Answers 2


I can't really think a a very suiting pattern. It looks like a mix a both a strategy pattern and chain of responsibility. The next link in the chain is then decided upon by the selected answer.

But a strategy implementation is defined compile time and I suppose that the question come from a database.

I do can imagine a very straight forward solution:

A Question class has a collection of possible Answers and the Answer class has a next question. This is actually a tree (directed graph), with the questions being nodes and the Answers the connecting edges.

The user interface navigates the tree using the answers.

This is both lean to develop and easy to maintain.


I could imagine such a system as a composition of components (questions) that can be asked in a random order.

I would design it on the architectural patterns level using namely Pipes and Filters architecture. Questions would represent filters and conditions would by implemented as pipes.

Pipes and Filters

This would result in a system, where you can really ask questions in a random order, because it is well known advantage of this architecture.

To get this working, you need to specify abstract class or interface for filters and pipes. Maybe, there can be only one implementation of pipe that will accept answer from a filter and decides what would be next filter in a pipeline.

Just a thought. Implementation would be probably harder.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.