OOA中的类设计

发布于 2024-12-27 22:55:42 字数 266 浏览 4 评论 0原文

我们想应用面向对象的设计来设计一个参加考试和得到结果的过程。 有两种不同的意见:

  1. 有2个对象:问卷和算法。调查问卷存储问题和最终结果,算法用于计算得到结果;

  2. 共有3个对象:调查问卷、算法和结果,这里将结果分离为一个对象,仅用于存储结果。

我的问题是哪一种是更好的 OO 设计?或者,在这种情况下,什么是正确的 OO 设计?

如果我想记录用户的答案,是否需要创建一个与问卷和算法相关的对象“答案”?

We want to apply object oriented design to design a process of taking an exam and getting the result.
There are two different opinions:

  1. there are 2 objects: questionnaire and algorithm. questionnaire is storing questions and the final result, and the algorithm is for calculating to get the result;

  2. there are 3 objects: questionnaire, algorithm and result, and here, the result is seperated to be one object which is just for storing the result.

My question is which one is a better OO design? Or, what is a correct OO design in this case?

If I want to record a user's answers, is it needed to create an object "Answer" which is connected with questionnare and algorithm?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

海未深 2025-01-03 22:55:42

你的第二个设计比第一个更好。

如果稍后您想生成报告,只需收集所有 Result 对象并准备即可。

并且,每个问题都会附加一个 Answer 对象。因此,Questionnaire 将包含 QuestionAnswer 对象的列表。

例如:Questionnaire对象可能包含以下属性:

  1. Id或RollNo。
  2. 姓名。
  3. 日期。
  4. 主题。
  5. 问题列表
  6. 答案列表。

5& 6 可以组合成 Question 对象列表。并且该对象可以由Answer对象组成。因此,仅问题列表就足够了。

如果我想记录用户的答案,是否需要创建一个与问题和算法相关的对象作为“答案”?

不,算法不需要连接(例如组合)到答案。它应该将 QuestionAnswer 作为输入并返回 Result

我的问题是哪一种是更好的面向对象设计?或者,在这种情况下,什么是正确的 OO 设计?

找出我们系统的不同用户、他们的期望、明确的和明确的期望。隐式需求、输入格式、输出格式,您将发现您的设计。

例如:

用户将如何提供答案?是简单的文字,主观,客观,有多少种选择? ETC...

Your 2nd design is better than 1st.

If later you want to generate report, just collect all Result objects and prepare it.

and, Each question will have an Answer object attached to it. so Questionnaire will contain a list of Question and Answer objects.

For example: Questionnaire object may contain following attributes:

  1. Id or RollNo.
  2. Name.
  3. Date.
  4. Subject.
  5. List of questions
  6. List of answers.

5 & 6 can be combined to list of Question object. and this object may be composed of an Answer object. So, only List of questions will suffice.

If I want to record a user's answers, is it need to create an object as "Answers" which is connected with questionnare and algorithm?

No, Algorithm need not be connected (such as composition) to Answer. It should take Question and Answer as input and return Result.

My question is which one is a better OO design? Or, what is a correct OO design in this case?

Find out the different users for our system, their expectations, explicit & implicit requirements, Input format, Output format, and you'll discover ur design.

For example:

How a user will provide answer? is it simple text, subjective, objective, how many options? etc...

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