I have a Request class based on the same Entity in my Domain. It currently only has property definitions. I'd like to add a method for checking a duplicate Request which I'll call from my controller. Should I add a method called CheckDuplicate in the Request class? Would I be violating the SRP? The method will need to access a database context to check already existing requests. I'm thinking creating another class altogether for this logic that accepts a datacontext as part of its constructor. But creating a whole new class for just one method seems like a waste too. Any advice?

  • If I had my way, all classes would have only one method unless that class was a container for logical groups of methods. But I'm a little extreme ;). Commented Jul 28, 2013 at 22:59

2 Answers 2


I'd go ahead and create it.

As you mentioned, adding a new responsibility to what's currently a DTO would violate the SRP. The question arises, what happens when the next requirement comes along? Would you add another method? What happens when you add a new attribute to the DTO? Would that necessary change add the risk of messing up your duplicate checking logic? Part of the idea of the SRP is that there should only be one reason to modify your class.

Moreover, a DuplicateChecker may turn out to be useful for other domain classes as you move forward.

It's not like classes are particularly expensive.


As per the question, you just need to validate if the entry is a duplicate? If thats the case that is like validation, so you can go ahead and create a method isValid() or isDuplicate() which would return a boolean value on checking the validations that you have.

  • not necessarily. I only need to check when a certain class of users are about to begin requesting. So the request isn't even complete yet. This is not being checked at submission of request.
    – Riz
    Commented Jun 28, 2013 at 17:20
  • @Riz Yes true, what I mean is, if you have this validation for certain users, then you call the isValid() method only for those users and if it is true, then proceed further.
    – JNL
    Commented Jun 28, 2013 at 17:25

Your Answer

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

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