Validation logic (and my first post!)
Hey all!
This is my first post since I joined Interface21 last month. My previous blog is now officially deprecated and I won’t be updating it anymore.
So what is the subject of my first post (except to introduce myself)? Validation logic. It won’t be a walkthrough of how to perform validation in the Spring framework, rather it will discuss a particular bug bear of mine :)
In particular, I would like to discuss exactly what should go into validation logic. It seems to be a no-brainer answer; “logic to validate the specified data”. OK, that is a no-brainer but read on :).
As you know, the Spring framework provides a nice abstraction layer for your validation, via the Errors and Validator interfaces. In particular the Validator is where you apply your business specific validation rules to your populated domain object. Spring’s excellent binding support is responsible for updating your domain model based on some input, the validator is responsible for ensuring that the populated domain model is semantically correct.
So what is my bug bear? Time and time again I keep running across applications that allow validation logic to trickle out of the validator and into the controllers (for web apps), or even worse into the middle tier. Just before people start taking issue; I am not saying validation doesn’t belong in the middle tier, I am saying that the Validator is the place to put validation logic!