One of the things that requires a realignment in thinking when moving away from RAD development tools as a means of solving business problems into a Domain Driven approach is where to put validation
and how to provide meaningful messages back to the user when something goes wrong.
It seems to me that a good indicator of an anemic strategy for validating data is lots of work being done with validation controls and checks at the presentation (view) level. That doesn't
mean that careful validation and thoughtful strategies at this layer are useless, but rather we shouldn't DEPEND on this layer to guard our datastore from bad data. Personally, I love
using Peter Blum's Validation Controls for my web pages because he has taken great pains to create a rich set of controls that do one thing VERY
well...validate at the client-side. Still, before I implemented a rich validation scheme across my layers in my app, I was spending TOO MUCH time with these controls to do work that
belonged in the Domain Layer.
A neat approach to validating entities in the Domain layer can be found on JP Boodhoos site where he has a
thorough explanation of a kind of reactive validation scheme. It's simple and easy to implement as well as flixible, should you want to apply different rules on the same entities.
After being careful in validating data and implementing strategies in the 'lower layers' I discovered that I had to do very little to guard my user's input from garbage data. All of a sudden, I didn't have
to have a ton of validation controls checking conditional comparisons or making sure data was complete before posting because the thoughtfulness that was applied to the domain layer bubbled up
to how I designed my User Interface strategy.
So for me, when I find myself having to accomodate complex rules in the User Interface, I need to take a step back and see if there is some insight in the Domain Layer that i haven't
gotten yet...for example,
- Is there YAGNI lurking in my design that might simplify things vertically across the layers?
- Did I let my own business specs creep in, or are my requirements actually coming from the stakeholders?
- Am I building my User Interface TOO SOON? Maybe I need to understand my domain better if I am adding and deleting controls like crazy.
These are good questions to ask when i am sticking a million validation controls on my page.
I kind of think of clientside validation like the guys with the bows and arrows on top of the wall around the city when the Orcs are marching in with their bad typing skills. They can take out
quite a few of the bad guys, but really the heart of the protection is going to take place by the fellas in the Domain layer with their swords and magic wands. The women in my database are relying
more on the guy with the battle axe than the guy with the slingshot.