I was doing this stuff a few years ago: Using Annotations to add Validity Constraints to JavaBeans?. And it wasn't really new then either as best I recall.
We were building a simulation system for water flow, and various modules had parameters with different units, valid ranges, constraints and all sorts of things. So inspired by an earlier project I had worked on, I decided to add tags in the javadoc blocks to declare these constraints and so on. We then wrote a javadoc plugin to process them and generate extra code to handle the validation.
Gee, maybe I should have patented it?
It can be an incredibly useful way of doing things. I am a big fan of using declarative styles where possible. And now that Python has decorators, the possibilities are amazing...

Leave a comment