I am not going to go on a rant here about how ColdFusion absolutely needs static variables. Instead I would like to present a use case from a recent experience and I would like to get your thoughts on it. I was working on a personal open source project called Hyrule. This project allows you to do validation on business objects (beans/ORM Entities/etc) by describing constraints in your objects.

Currently you can describe these constraints using annotations. I found out in a recent project though that this can get very messy. Having played around with Grails before I really enjoy being able to define my constraints like this. I thought why not create a similar way to describe constraints for Hyrule, so I set out on my mission

My first attempt went pretty well. I created a new Validator to handle constraints based settings and ended up with a model that looked like this. I was really happy with this and it seems like a much cleaner implementation than having a million annotations running around. Then a friend pointed out something that I totally overlooked. This method would not support inheritance. You can not access the this scope from a parent object. So if we had an employee object that defined its own constraints and extended User we would never be able to get the user constraints. This obviously brings up a huge issue and killed any dreams I had of implementing this.

So here is my use case for static variables in ColdFusion. In case your not quite sure what static variables lets review. A static variable can be accessed from a class without instantiating that class. So going back to our example say we have 2 components here, person and employee. Employee Person

Now when if create an instance of the employee object we can use meta data to find out if the component extends any other components (inheritance) and if it does we would have the full name of the component. From there it would simply be a matter of accessing the variable constraints. I am not sure how the implementation would be that would be the basic idea behind it. So that is my case let know your thoughts on static variables/methods in general. I would also be all ears in figuring out a different solution to my little problem here.