3

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?

1

1 Answer 1

1

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...

Sign up to request clarification or add additional context in comments.

4 Comments

Should the Questionnaire Object hav a reference of the Result Object ?
Yes, it should. How will you identify that which Questionaire matches to which Result. OR you can simply have common id in both objects. but i'll prefer former.
questionnaire algorithm and result class are abstract classes, i just need to pass the correct type of algorithm to result, I can get the certain result,isnt it?
Oh, yes. This way is also looks good. based on different Algorithm passed, a different Result will be prepared. But ideally it should not be job of Result to prepare itself.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.