# Does this method contain multiple implementations?

My teammate and I have a small discussion about the responsibility of a method. He thinks next method has two responsibilities and I think that only one.

 private boolean validateUsername(String username) {
AccountValidationResult validationResult =

if (!validationResult.isSuccessful()) {
} else {
}
return validationResult.isSuccessful();
}


I think that the responsibilities of validating the string "username" falls on the "validate" method of my mAccountValidator collaborator. Depending of the result returned by my collaborator, I change the state of the view and finally, in order to finish the process or not, I return the state of validation. This result is managed by the next method:

public void doLogin(UserCredentialModel userCredential) {

return;
}

return;
}

}


What do you think about my solution? Do you think that is it enough clean or how I could improve it?

Thank a lot for your time and help.

• Do you want to know what it does or how to make it better? It reads like you're posting 2 questions here and only one of them is on-topic. – Mast Jul 19 '16 at 10:03
• Well, I would like to know if validateUsername contains multiples responsibilities or not. If it is true, I would like to know how improve it with a clean solution. – juanjo Jul 19 '16 at 10:47

Seemed fine at first, then I took another look...

The validation function displays the error message?

I'm sorry, but that's indeed a violation of SRP. You'd be better off returning a ValidationResult which you could use. You already HAVE this validation result... so in a way, you've already done what I said.

What's wrong is that your function names do not reflect this. You call validateUsername, but it also displays errors. Rather than changing the validation method to return a ValidationResult (which would imply taking out validateUsername and doing everything in doLogin, you should change the function name instead.

• validateUsername method notifies to the view that one error happened. => View.setUsernameModeError(validationResult.getMessage()); – juanjo Jul 19 '16 at 10:51

After reading the code, I came to the same conclusion that @Pimgd did, that validateUsername seemed like the wrong name for the method.

This isn't really what you were after, but this:

AccountValidationResult validationResult =

Seemed odd to me. Obviously I've not seen the contents of AccountValidation or your validators, but it seems odd to me to tell a validator to validate and still have to pass it an argument that contains a parameter VALIDATION_REQUIRED. It does make you wonder what else is going on there.