OOA中的类设计
我们想应用面向对象的设计来设计一个参加考试和得到结果的过程。 有两种不同的意见:
有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:
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;
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你的第二个设计比第一个更好。
如果稍后您想生成报告,只需收集所有
Result
对象并准备即可。并且,每个问题都会附加一个
Answer
对象。因此,Questionnaire
将包含Question
和Answer
对象的列表。例如:
Questionnaire
对象可能包含以下属性:5& 6 可以组合成
Question
对象列表。并且该对象可以由Answer
对象组成。因此,仅问题列表就足够了。不,
算法
不需要连接(例如组合)到答案
。它应该将Question
和Answer
作为输入并返回Result
。找出我们系统的不同用户、他们的期望、明确的和明确的期望。隐式需求、输入格式、输出格式,您将发现您的设计。
例如:
用户将如何提供答案?是简单的文字,主观,客观,有多少种选择? 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. soQuestionnaire
will contain a list ofQuestion
andAnswer
objects.For example:
Questionnaire
object may contain following attributes:5 & 6 can be combined to list of
Question
object. and this object may be composed of anAnswer
object. So, only List of questions will suffice.No,
Algorithm
need not be connected (such as composition) toAnswer
. It should takeQuestion
andAnswer
as input and returnResult
.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...