Over the last few days, the concept of a validation engine for ColdFusion has been tossed around in several blog posting ( Form Validation – How do you do it?, Form Validation – The Rules Live Where? ). One of the primary goals being discussed for that validation engine is flexibility. In other words, the validation engine must be able to be dropped into any scenario with as little customization as possible.
Reusable Validation Plug-ins
When you think of validation, one of the first things that comes to mind, is all of the validation rules that the data must be checked against. How do you make a validation engine that has rules for every possible case? The short answer is you don’t.
Instead of making this super smart validation engine that knows how to do anything, one possibility is to use plug-in validator modules that give the validation engine a way to validate data. For example, if you wanted to be able to validate dates, you might have a DateValidator component that was injected into the validation engine. That component would have a known interface which the validation engine could then used to validate data that should be of type date.
By following this style of model, it would be very easy for a developer to inject a series of specialized validator components into the validation engine to fit the requirements of their specific application.
Pluggable Validation Engine
In the comments for one of my earlier postings, Peter Bell mentioned that his preference is to insert data into business objects (beans) and validate it there rather than validate arbitrary strings or structures. While this is not my personal preference, I was talking with Doug about this and the question arose … why not make the validation engine flexible enough to do both?
What if, in the same manner as the plug-in validator modules, the validation engine itself was pluggable in the way it obtains the data to validate? What if there was a structure reader plug-in (for lack of a better term) that knew how to get all of the key / value pairs from a structure and treat those as data values to validate? Along the same lines, there could be a bean reader plug-in that knew how to get the meta data for a business object and use all of the getter functions to get the data from the bean to validate.
This concept is still up in the air, but I wanted to throw it out there and see if anybody else had any thoughts or ideas?