What is the difference between a validation rule and a business rule ?
As per my understanding, 'if the state of the business object/objects is not as expected, then throw an error message' is a validation rule, and 'when the state of the business object/objects is or is not equal to something, then change the state of some business object/objects [or take some action/event but not just throw an error]' is a business rule.
Validation can be UI validations - validate values of UI fields or application validations - validate business object states.
I am not sure whether my understanding above is correct. In my project, we have a validation framework, where a simple validate call takes business objects to validate against something and an error collector that collect all errors. The errors are displayed on the screen afterwords.
In addition to that, we have rules that falls in second category as described above i.e check the business object/objects state and take some action such as change the state of another business object. I am trying to find out the strategy to implement such rules either using some framework [not a validation framework] or a rule engine.
Can you please help me understanding the distinction between the above 2 kind of rules and if there are any implementation strategies/ recommendations, it would be helpful.
A validation is a check that the value entered is legitimate for the context of its field (from technical perspective), for example: is 5 as a numeric value acceptable for Age(v.s. -5)?, while -5 is acceptable as Temperature for example.
The business rule is more of a business perspective. It is a check that the values (that passed the validation) are acceptable by the policies and procedures of the business. E.g. the person who is allowed to register has to be a resident, and 18 years old or more..etc. The business rule might check one (or more) field(s) value(s), and might consult data stored in a database and/or do some calculation(s) to ensure that the value(s) pass the business rules.
So, for the example posted above by hanna, the value 15 should pass the field validation (as it is a valid value for Age), but it will not pass the business rule check that the married person's age must be >15.