I have a hierarchy of classes, each category represents a variety of questions in a survey.
So far, users can give a single answer to the question (from input box, ratio button or dropdown). The answer to each question is stored in the form of a string inherited from the question
in the answer
field.
The hierarchy is done to add a multi-option question to me. A multi-choice question can provide many answers to users (like selecting multiple options in a group of checkboxes, or through multiple text boxes ).
In the picture below, the green square should add to me. My problem is that the present structure considers only one answer.
I have thought of two possible modifications:
- Encoding multiple responses as a CSV and giving them the
Answer
field. - A new area
list & lt; String & gt; Adding
and a gettermultichoice
to answergetAnswers ()
I see problems in both ways. First person connects the responsibility of parsing the potential CSV to answer the caller. Second, Liskov violates the replacement principle.
My question is: how do I support many such problems in MultiChoice
?
< Div class = "post-text" itemprop = "text">
interface
list & lt; String & gt; Getanswers (); Zero addAnswer (string reply);
But this is a straight-object rather than an object-oriented design. For me it feels like a Visitor Pattern case like
Acceptor (Visitor v) is valid;
and
Interface Visitors & lt; T & gt; {T visit (T AGR, dropdown answer); T Travel (TArg, Multichoice Answer); T visit (T AGR, answer to single rice); ...}
with a solid response type per visit method. And then apply the figures on the answer as the visitor's implementation, if there are data you want to do, however, do not always be in the dump areas, think about what you want to do with the data.
No comments:
Post a Comment