I am creating a testing program. The three main objects I have right now are Tests, Questions, and Answers. I have three tables in the database, tests, questions and answers and a FK from questions to tests and a foreign key from answers to questions. As part of the questions table I have a column called correct_answer_seq_num which stores the seq_num (unique identifier) of the answer that is the correct answer to that question. I decided to put this attribute in the questions table, because only one answer can be the correct answer (for this specific test; I know there are tests where that is not the case), and if I put it in the answers table, then you could mark all answers as correct.
The trouble I am having is which object I should put this property in. Its not really an attribute of a question, it is more of an attribute of an answer, but I still think it should be in the question class for data integrity sake.
Am I making too big of a deal of this, and if not, where should I put the property?
I think the way you’ve done it in the database is correct and translates correctly into the model, too. Consider the following:
All three
Questionshave the same availableAnswers, and it’s only when anAnsweris related to aQuestionand placed amongst otherAnswersthat you can say whether it is correct. AnAnswertherefore has no ‘correctness’ without being associated with aQuestion, which makes anAnswer's‘correctness’ a property of aQuestion, not anAnswer. This is especially true if the sameAnswercould be associated with multipleQuestions– correct for some, incorrect for others.So to sum up, I think
Question.CorrectAnswermakes more sense thanAnswer.IsCorrect.Finally, I think it is worth making a big deal out of this sort of thing, as if you’re not comfortable with your design decisions and the structure of your model it’s probably a sign that something isn’t right 🙂