1

I previously asked this question on Code Review but was told this was 'off-topic' so I am trying it here. I hope someone can help guide me.

As part of an insurance claims system we have created, the claims managers can log incoming telephone calls relating to a claim.

The claims manager must validate the caller by asking a number of 'Data Protection' questions that are generated dynamically from information stored against the claim in a database. I believe this type of security is known as 'knowledge-based authentication'.

Notes:

  • Some questions are mandatory and some are not.
  • All mandatory questions must be answered.
  • At least one non-mandatory question must also be answered.
  • Each question may have multiple correct answers.
  • Answers are also generated dynamically from information stored against the claim in a database.
  • The claims manager selects an answer from the generated list of answers for each question that closely or exactly matches the caller's response
  • The list of answers for each question must include an 'Unanswered' (default) and 'Incorrect Answer' option

The current system was written five years ago and we did not attempt to use any design patterns or modern approaches (such as Domain-Driven Design) because we lacked the time and understanding.

We now have the opportunity to re-write this software and would like to follow a Domain-driven approach.

Here is my simplistic attempt to model the above requirements:

public class DataProtection
{
    public IEnumerable<DataProtectionQuestion> DataProtectionQuestions { get; set; }        
    public bool DataProtectionValidated =>
        DataProtectionQuestions.Where(x => x.IsRequired).All(x => x.AnswerIsCorrect) &&
        DataProtectionQuestions.Any(x => x.IsRequired == false && x.AnswerIsCorrect);        
}

public class DataProtectionQuestion
{
    public IEnumerable<string> Answers { get; set; }        
    public string Question { get; set; }
    public bool IsRequired { get; set; }
    public string Answer { get; set; }
    public bool AnswerIsCorrect => Answers?.Contains(Answer) ?? false;
}

Questions that arose from this design:

  • Would these entities be considered anaemic according to Uncle Bob?
  • Is the DataProtection entity the 'right' place to validate the answers?
  • Should an Answer be an entity in its own right with a property for 'IsValid'?

Can anyone please offer some guidance / suggestions on a way forward / better approach?

0

Would these entities be considered anaemic according to Uncle Bob?

Wasn't it Martin Fowler that coined the "Anaemic" term? Anyway, I would say "No" he would consider the DataProtectionQuestion a data struct and not an object. MF might disagree.

Is the DataProtection entity the 'right' place to validate the answers?

Hard to say. I don't like your example object. I can see that the evaluation of the answered questions could be more complex that your simple function, and thus you would want to be able to replace out the business rules. I would have something like :

public class DataProtectionForSituationX : IResultEvaluator
{
    public bool DataProtectionValidated(IEnumerable<DataProtectionQuestion> answeredQuestions) {...}
}

Should an Answer be an entity in its own right with a property for 'IsValid'?

Yes. You will want to store, pass and consume Answers without worrying about whether they are valid and their validation could well depend on information external to the Answer as well as temporal information.

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.