I usually use a specification class, it provides a method (this is C #, but you can translate it into any language):
bool IsVerifiedBy(TEntity candidate)
This method performs a full check of the candidate and his relationship. You can use the arguments in the specification class to make it parameterized, for example, the check level ...
You can also add a method to find out why the candidate has not confirmed the specification:
IEnumerable<string> BrokenRules(TEntity canditate)
You can simply decide to implement the first method as follows:
bool IsVerifiedBy(TEntity candidate) { return BrokenRules(candidate).IsEmpty(); }
For broken rules, I usually write an iterator:
IEnumerable<string> BrokenRules(TEntity candidate) { if (someComplexCondition) yield return "Message describing cleary what is wrong..."; if (someOtherCondition) yield return string.Format("The amount should not be {0} when the state is {1}", amount, state); }
You must use resources for localization and why not pass the culture to the BrokenRules method. I put these classes in the model namespace with names that suggest their use.
thinkbeforecoding Feb 06 '09 at 22:21 2009-02-06 22:21
source share