Tuesday, October 27, 2009

Validation and Business Rules

From Rocky Lhotka’s Business Objects pg 40: “A lot of business logic involves the enforcement of validation rules. The fact that one date must be later than another date is a validation rule. Some validation rules involve calculations and others are merely toggles. You can think about validation rules as being either broken or not. And when one or more rules are broken the object is invalid.

A similar concept is the idea of business rules that might alter the state of the object. The fact that a given piece of text data must be all uppercase is a business rule. The calculation of one property value based on other property values is a business rule. Most business rules involve some level of calculation… Business rules typically alter the state of the object and usually don’t enforce validation at the same time.”

A comment on Ayende Rahien’s blog article:

“Name is not empty is an invariant of the entity. Not a business rule because it is not something that can happen (yes, I know about bad data and no constraints).”

0 comments: