When LCF made static methods available I didn’t initially use them that much. Lately I find that I’m using them more and more. I like the handiness of having a method available to me in a cfc without the overhead of having to create an instance just to access one or two methods from within it. As an example I have a formvalidation.cfc
. One of the methods it offers is the removeQuotes method. The init method requires a form structure to be sent. There’s a whole lot of stuff the formvalidation.cfc looks for but if I just wanted to use the removeQuotes method I would have to submit a bogus structure with the field values I wanted to check. Now I can just call formvalidation::removeQuotes( fldValue )
. I find that I’m using this a lot.
In structuring things this way I stumbled across something interesting, it was new to me anyway. You can have a method name in all access modes. In the formvalidation.cfc I have a public removeQuotes method and a static removeQuotes method. I thru in a private removeQuotes method to see if that worked and it did. I got rid of it after the test.
I’m mostly curious what the pro’s and con’s might be of using static methods as opposed to instance methods.