1
votes

There are two classes: Question and Answer. Instance of Question contains a list of Answers, each Answer points to a follow up Question. So each selected answer triggers a relevant next question until answer with no followup question is selected.

What would a UML diagram look like to best describe a questionnaire flow like this:

Q1: "Are you hungry?" [Yes, No]
  Yes->Q2: "What do you want to eat?" [Apple, Pear, Banana]
      Apple->Q4: "Green or red?" [Green, Red]
      Pear ->Q5: "Big or small?" [Big, Small]
  No ->Q3: "Are you thirsty?" [Yes, No]
      Yes->Q6: "What would you like to drink?" [Tea, Coffee, Water, Vodka]
          Tea  ->Q7: "Any sugar?" [1 spoon, 2 spoons, 3 spoons]
          Vodka->Q8: "Are you old enough for it?" [Yes, No]      

A class diagram would describe relationship between the classes but not the question-answer flow.

Object diagram would have too much information about relationship between objects and the object's inner structure which would make it hard to read the question/answer flow which we are interested in.

Activity diagram would work well if questions were true or false, then the decision diamond shaped icon could be used for the true and false flow. But that wouldn't work if a question has 7 possible answers.

So my problem is to find the type of a diagram that would describe a flow like that in the most basic and clear way.

2
I'm voting to close this question as off-topic because "3. Questions asking for homework help must include a summary of the work you've done so far to solve the problem, and a description of the difficulty you are having solving it."xmojmr

2 Answers

1
votes

Different diagrams are are used for different things and provide different model of details. If you want to present relations between classes in you model then class diagram with two associations

Question 1 <-- answers --> 1..* Answer
Answer 1 <-- follow-up --> 0..1 Question

will be just fine (I intentionally do not say anything about the classes because I do not want to suggest implementation). In some tools like for example Enterprise Architect you can use this diagram to generate source code. Based on you question I think this is what you want.

If you on the other hand want to show control flow then you should use one of behaviour diagrams. Sequence or communication diagrams show how objects of your model interacts (which methods are used) with each other to implement specific use case. If you use states in you model then you can show it on state machine diagram.

0
votes

It seems that you are confused about the two possibilities of describing/modeling a "process flow":

  1. at the type level where you describe a Q&A process type
  2. at the object/instance level where you describe a specific Q&A process such as the one about Q1, Q2, etc. in your exmple.

You can use an object/instance-level model for describing exmples or for designing content.

But for designing a software application, you need to model at the type level. But the flow pattern of your problem is so simple that you don't need any behavioral model, really. It's entirely underdstandable from the class diagram (as sketched in Marek Adamek's answer) where the flow loops from a question to one of its possible answers, and then to this answer's follow-up question (and then to the next iteration).