What is the difference between a validation rule and a business rule?

Viewed 14379

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.

5 Answers

It all depends on perspective. Both validation rules and business rules are really the same thing. We sometimes logically categorise how complex rules are, the most basic being Validation then more complex being Business rules. That's not correct, as it depends! Example of "complexity rule hierarchy":-

Basic datatype

Usually conversion from a string into strong type, examples

  1. A number cannot be "hello"
  2. Boolean is yes/no or True/False.

Metadata on type/common sense

Now we have a strong type, check bounds, getting more blurry

  1. Future booking date is not historic (before now)
  2. Year in century, number in range 1 to 100
  3. Notes max 100 chars.

Business rules

Now fully ambiguous...it depends!

  1. If System Health Check account then Email is mandatory but must be malformed "not-an-email".
  2. Cannot place order more than 1000USD, if credit limit is "Basic"
  3. Notes must be min 200 chars if is Manager.

Did you notice a Manager must make 200 chars of Notes minimum, whilst others zero to max 100. Thus some may argue max chars is validation, but clearly the business requires Managers do more. So which is it?

Maybe call everything a Business Rule as the ultimate goal of validation is to ensure "data correctness in all business contexts".

Related