There's no definite answer that can be derived from the business logic. Both approaches are equally valid. I'd take a more pragmatic view:
- If your password checking algorithm is simple then I would place the
CheckPasswordRequirements
method directly in thePassword
class and call it in the c'tor. - If the algorithm is more complex or will possibly be subject to change in the future, then you're better of with a separate Utility class (named something like
PasswordChecker
). As a variant, you could also do this in form of an extension method:
static class PasswordExtension
{
public static bool CheckPasswordRequirements(this string password)
{
//Some logic here
}
}