Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

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.

share|improve this question

migrated from stackoverflow.com Mar 30 '13 at 13:39

This question came from our site for professional and enthusiast programmers.

    
@Juhana Is there magic button to migrate or I just need to delete the question and then repost on programmers? –  voroninp Mar 29 '13 at 11:08
1  
You can flag the question and write a comment to the moderators. –  Juhana Mar 29 '13 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. –  Theo Lenndorff Mar 30 '13 at 13:46
add comment

2 Answers 2

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.

share|improve this answer
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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