I have a class similar to ServletFilter which has multiple validation on the input request
class TokenHandler implements SomeHandler{
Response handle(Request request){
if(paramXMissing(request)){
return new Response(); // empty response
}
if(paramYGreaterThan100(Request request)){
return new Response(); // empty response
}
//some more similar validation on request
}
}
request
parameter can be an instance of any subtype of Request
. As most of the validation methods depend on Request
instead of the Handler, this seems more like feature envy code smell. Had Request
been a normal domain object I would have just Moved method to that class. But in this case, how do I refactor this code (Long method)?
I am not sure if introducing a new Validator class would be a right choice.
Edit
I don't have just the validation, but also additional processing on request object, for instance, remove particular parameter from query string.
I actually think that introducing new classes for each specification would be an overkill. Is it really required? Any other alternative?
Request
I would most likely pass it via constructor parameter into thatSpecification
class discussed in this answerspecification
classes for each condition? Doesn't it sound like an overkill?