I would argue that the validate routines be their own classes; ie
UserInputValidator
,UserPasswordValidator
, etc.
I wouldn’t. Not from this example anyway. YAGNI is an important paradigm and introducing plenty of classes upfront to implement trivial checks is overengineering typical for Java and the reason I don’t like it.
Edit: Your naming convention isn’t the best either. I’d expect UserInputValidator
to validate user input, maybe sanitize it for a database query, but not necessarily an existence check as in the example.
Oops, right, I just glanced over the code and obviously missed the text and code had different class names. Another smell in my opinion, choosing class names that only differ in the middle. Easily missed and confusion caused.
I don’t think our opinions are too far off though. You’re just scaling the validation logic to realistic levels and I warn that in practice coders extrapolate too quickly and too often, which results in too much generic code which is naturally harder to understand and maintain than specific code.