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 =
mAccountValidator.validate(username, new int[]{AccountValidation.VALIDATION_REQUIRED});
if (!validationResult.isSuccessful()) {
mView.setUsernameModeError(validationResult.getMessage());
} else {
mView.setUsernameModeStandard();
}
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) {
if (!validateUsername(userCredential.getUsername())) {
return;
}
if (!validatePassword(userCredential.getPassword())) {
return;
}
mDoLogin.setUserCredential(userCredential);
mDoLogin.execute();
}
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.