0

I'm working on a project with has different checklists (questions and answers) associated with an entity (Protocol). There is a business requirement to have these questions be altered in the future and when a new entity is created it would be associated with the current checklist.

Example:

Lets say there is a checklist and has 21 questions (the actual questions are nested with questions having other questions but I believe this is out of the scope of this question). This would be version 1.0. Something changes and now there are 22 questions and the version would be bumped up to 1.1.

When a new Protocol is created, it needs to have a Checklist associated with it - the current Checklist.

Simplified classes:

class Checklist {
    String version
    List<ChecklistQuestion> checklistQuestions
}

class ChecklistAnswerSet {
    Checklist checklist
    List<ChecklistAnswer> checklistAnswer
}

class Protocol {
    ChecklistAnswerSet checklistAnswerSet
    ...
}

New Protocol's are created within the ProtocolService; the child checklistAnswerSet is also created here as well but needs to refer to the current Checklist instance.

We are working with a grails backend and it's extremely easy getting references to instances by their fields:

Checklist checklist = Checklist.findByVersion('1.1')

I could drop this in my ProtocolService to get the current instance but I know this isn't a good idea. Any changes to this version would require code changes to the Service and although I could avoid a redeploy (grails magic), this feels completely wrong.

Where do I store this 1.1? In a configuration file? In the database? Or am I completely wrong and my design needs a complete rework?

Initially, I was storing this 1.1 data within a generic key/value table we have in the database called System_Property, but it just felt wrong. My gut reaction is to use a configuration file (there are other Checklist's and therefore other current versions that would also go here), but a coworker is saying only environmental settings go in config files.

1

For a complete solution merely storing the version would not enough, simply because

  1. You could delete a question in the subsequent version and you still want to keep the answers for the previous versions
  2. When you alter a question, the if the answer still linked to the changed question, it won't make sense once the question is changed

So ideally, you would want to store something like this,

class Checklist {
    List<ChecklistVersion> checklistVersions
}

class ChecklistVersion {
    String version
    List<ChecklistQuestion> checklistQuestions
}

class ChecklistAnswerSet {
    ChecklistVersion checklistVersion
    List<ChecklistAnswer> checklistAnswer
}

class Protocol {
    ChecklistAnswerSet checklistAnswerSet
    ...
}

by adding a separate version object, you would not have issues if a question is deleted, or new one added or existing one changed

  • Thank you for your input. I did not go into detail for the ChecklistQuestion/ChecklistAnswer classes but the answer has a reference to the question which is backed by a foreign key so a deletion would not occur (a question may not appear on future checklist though). I believe altering of questions would only occur to correct minor errors; we would create a new question if the meaning actually changed and replace it within the new checklist. – tylerwal Feb 17 '16 at 0:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.