oopdesign-patternsobject-oriented-analysis

classes design in OOA


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?


Solution

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