OOP class design conondrum. I am designing a set of classes for an online survey/quiz engine. I need some help with designing my classes.
Preface, I am writing this in C# and the project is an attempt to teach myself proper OOP. I am working my way through the Head First Design Patterns Book
and understand the SOLID design principles
but I lack experience in applying them and am not even sure which pattern if any will solve my problem. I also fear I may lack the vocabulary to properly describe my question so I will be monitoring this thread to give any additional information needed to solve it.
Here the main classes:
Here is what I think you need to know about the classes:
Each Candidate is Assigned a single Assessment.
Each Assessment contains a number of Tests.
Each Test has a QuestionSet
Each QuestionSet has a series of Questions
Each Question has a set of possible Answers
My difficult is knowing how to design the relationship between the Assessment and the Candidate. Here is where I am stuck:
Candidate objects have an Assessment member which gives access to the whole Assessment hierarchy. So when they login in I can easily access the tests in the assessment, when they select a test I can easily output the questions and possible answers for them to complete. However the way I have designed the Assessment to Answers objects hierarchy does not accommodate information on which tests have been taken by a Candidate to date nor which responses the Candidate has provided. Why you ask? Well I am getting the Assessment details from a Data Access Layer and as they rarely change I want to cache each Assessment object to avoid a major round trip to the database each time someone takes a test. If I am to redesign this hierarchy of objects to include information on which Tests have already been taken by the Candidate I will be unable to cache the Assessment even though it will be the same for everyone when they login for the first time. I also need to be able to store the Candidates ResponseSet which records the answers they provides to the questions, I will also need to allow for information like when the test was started how long it too etc.
In its simplest terms I have defined the Assessments and all associated objects as it if they make up an untaken set of tests, a blank test workbook if you will. Everyone should get the same one when they start, hence the desire to cache them. However when the candidate is finished with the workbook each one will be different and am at a loss as to how to handle (in the class design) the information the Candidate provided .
How can I best design this set of classes to allow for maximum data caching while adhering to good design practice?