I personally don't like programming arround / Enum return values. The more return types you have, the more ways you should test / work with. Also, using exceptions for the control flow is bad practice (if you really cannot find any other option, but it is usually better).
The expired password is not exclusive to me. Its legal state in the end (otherwise you would do something against passwords to expire at all)
I am trying to keep it simple and either return a bool or something like Func<T> that could be called by the caller.
Maybe something like this:
public class User { private DateTime _lastChangeDate; public Action Validate() { if (_lastChangeDate >= DateTime.Now.AddDays(-30)) { return new Action(() => this.Login()); } else { return new Action(() => this.ChangePassword()); } } private void Login() { Console.WriteLine("Login"); } private void ChangePassword() { Console.WriteLine("Change Password"); } }
From the side of the subscriber:
user.Validate().Invoke();
Alex
source share