我应该把这个对象属性/属性放在哪里
我正在创建一个测试程序。我现在拥有的三个主要对象是测试、问题和答案。我在数据库中有三个表:测试、问题和答案,以及从问题到测试的 FK 和从答案到问题的外键。作为问题表的一部分,我有一个名为 Correct_answer_seq_num 的列,它存储答案的 seq_num (唯一标识符),该答案是该问题的正确答案。我决定将此属性放入问题表中,因为只有一个答案可能是正确答案(对于此特定测试;我知道有些测试并非如此),如果我将其放入答案表中,那么您可以将所有答案标记为正确。
我遇到的麻烦是我应该将此属性放入哪个对象中。它实际上并不是问题的属性,它更多的是答案的属性,但我仍然认为出于数据完整性的考虑,它应该放在问题类中。
我是否把这件事看得太重了?如果不是,我应该把财产放在哪里?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您在数据库中完成的方式是正确的,并且也可以正确转换为模型。请考虑以下情况:
所有三个
问题
都具有相同的可用答案
,并且仅当答案
与问题
相关时才有效code> 并放置在其他答案
中,您可以判断它是否正确。因此,如果不与问题
关联,答案
就没有“正确性”,这使得答案
的“正确性”成为的属性问题
,而不是答案
。如果相同的答案
可以与多个问题
相关联,则尤其如此——对于某些问题是正确的,对于其他问题是错误的。综上所述,我认为
Question.CorrectAnswer
比Answer.IsCorrect
更有意义。最后,我认为值得对此类事情大肆宣扬,就好像您对自己的设计决策和模型结构不满意一样,这可能表明有些事情不对劲:)
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
Questions
have the same availableAnswers
, and it's only when anAnswer
is related to aQuestion
and placed amongst otherAnswers
that you can say whether it is correct. AnAnswer
therefore 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 sameAnswer
could be associated with multipleQuestions
- correct for some, incorrect for others.So to sum up, I think
Question.CorrectAnswer
makes 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 :)