I'm been working on a GetRuleViolations()
method for my User
class, but I'm getting a little hung up on on something:
What happens when different actions require different business rules?
My User
table has the following columns: Id
, UserRoleId
, Username
, and Password
. Several actions involving User
are possible (create new user, edit user, set/reset password, and log in), and the business rules for each are not always the same.
For example, when users log in, they are required to enter a password, but when admins create a new user, entering a password is not even an option. And in the case of setting/resetting a password, the password needs to be entered twice, and the two values need to be an exact match. What is the best way to handle this complexity? Is there some kind of design pattern to allow the right GetRulesViolations()
method to be selected for the right circumstance?