Alex Rivera | Logout

Should Business Objects or Entities be Self-Validated?

Asked 2010-03-02T00:10:26.033
11

Validation of Business Objects is a common issue, but there are some solutions to solve that.

One of these solutions is to use the standalone NHibernate.Validator framework, which is an attribute-based validation framework.

But I'm facing into conceptual concern. Attribute validators like NH.Validator are great but the validation is only performed when save-update-delete within the Session.

So I wonder if business objects should not be self-validated in order to maintain their own integrity and consistence?

Edit
Report

1 Answer

7

It's not always possible for them to self-validate though. What if you enter an "invalid" Zip Code? You could validate that the Zip Code needs to be in a specific format, but what if you want them to be "valid", that is "existing and matching the city"? Or what if you only accept phone numbers from certain area codes, and the list of valid codes is in a database maintained by the legal department?

If you can perform semantic validation, that's great and could go into the Business Class. But often, you might need extra validation that is simply not possible to handle by the business class itself but needs to be handled by the class that talks to the database and other external services.

answered 2010-03-02T00:45:01.920

Your Answer