我应该把这个对象属性/属性放在哪里

发布于 2024-11-19 06:50:40 字数 361 浏览 12 评论 0原文

我正在创建一个测试程序。我现在拥有的三个主要对象是测试、问题和答案。我在数据库中有三个表:测试、问题和答案,以及从问题到测试的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

捶死心动 2024-11-26 06:50:40

我认为您在数据库中完成的方式是正确的,并且也可以正确转换为模型。请考虑以下情况:

Question  AvailableAnswers  CorrectAnswer
   1 * 1           1, 2, 3              1
   1 + 1           1, 2, 3              2
   1 + 2           1, 2, 3              3

所有三个问题都具有相同的可用答案,并且仅当答案问题相关时才有效code> 并放置在其他 答案 中,您可以判断它是否正确。因此,如果不与问题关联,答案就没有“正确性”,这使得答案的“正确性”成为的属性问题,而不是答案。如果相同的答案可以与多个问题相关联,则尤其如此——对于某些问题是正确的,对于其他问题是错误的。

综上所述,我认为 Question.CorrectAnswerAnswer.IsCorrect 更有意义。

最后,我认为值得对此类事情大肆宣扬,就好像您对自己的设计决策和模型结构不满意一样,这可能表明有些事情不对劲:)

I think the way you've done it in the database is correct and translates correctly into the model, too. Consider the following:

Question  AvailableAnswers  CorrectAnswer
   1 * 1           1, 2, 3              1
   1 + 1           1, 2, 3              2
   1 + 2           1, 2, 3              3

All three Questions have the same available Answers, and it's only when an Answer is related to a Question and placed amongst other Answers that you can say whether it is correct. An Answer therefore has no 'correctness' without being associated with a Question, which makes an Answer's 'correctness' a property of a Question, not an Answer. This is especially true if the same Answer could be associated with multiple Questions - correct for some, incorrect for others.

So to sum up, I think Question.CorrectAnswer makes more sense than Answer.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 :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文