A few notes on implicit vs explicit getters and setters.
1) Coldfusion support in CF9 is enabled on the property tag as an attribute – not on by default
http://www.danvega.org/blog/index.cfm/2009/10/6/ColdFusion-9-Implicit-getters–setters-change
2) Coldfusion onMissingMethod
http://www.bennadel.com/index.cfm?dax=blog:868.view
Although Ben Nadel seems to dislike the thing ( it was a while back so maybe he changed his mind?) – and he’s being convinced in the comments. The performance affect was exceedingly marginal (<20ms).
An implementation of what I was talking about is here:
http://www.coldfusionjedi.com/index.cfm/2007/8/5/Warning-about-onMissingMethod – the warning relates to using the right arguments. Comments suggested changing find to comparing the first 3 characters to improve performance.
<cfcomponent name="entity_auto" extends="ColdFX.entity" output="false">
<cffunction name=”onMissingMethod” access=”public” returnType=”any” output=”false”>
<cfargument name=”missingMethodName” type=”string” required=”true”>
<cfargument name=”missingMethodArguments” type=”struct” required=”true”>
<cfset var key = “”>
<!— this includes arguments with set —>
<cfif left(arguments.missingMethodName,3) eq “set”>
<cfset key = replaceNoCase(arguments.missingMethodName,”get”,”")>
<cfif structKeyExists(variables, key)>
<cfreturn variables[key]>
</cfif>
</cfif>
<!— this includes arguments with get —>
<cfif left(arguments.missingMethodName,3) eq “get”>
<cfset key = replaceNoCase(arguments.missingMethodName,”set”,”")>
<cfif structKeyExists(arguments.missingMethodArguments, key)>
<cfset variables[key] = arguments.missingMethodArguments[key]>
</cfif>
</cfif>
<!— everything else still throws an error —>
</cffunction>
</cfcomponent>
If you want to turn on auto magic dynamic proxying all you do in your component is
<cfcomponent name="car" extends="ColdFX.entity_auto" output="false">
<cfproperty name="wheels">
<cfproperty name="engine">
<cffunction name=”init”>
<cfargument name=”wheels”>
<cfargument name=”engine”>
<cfset this.setWheels(arguments.wheels)/>
<cfset this.setEngine(arguments.engine)/>
</cffunction>
</cfcomponent>
ColdFusion was the first time I had ever heard of handling methods that were not defined in objects. As such, I completely misunderstood what they were for (and was a bit misinformed as well).
Since that post, I have come to rather like onMissingMethod() and use it for fun and profit (as Dan Wilson would say).
I thought you would, I was trying to convince a few people at work that a couple of implicit getters and setters would help us. They were unconvinced, so I found a few backup sources. I think its a great feature
Tests have shown that the implicit getter/setter (intro. in CF9) are much much more efficient than onMissingMethod() (intro. in CF8).
Henry,
Interesting – but as coldfusion8 took 2 years to arrive here. We can’t really wait that long.
.
Joel
If performance is important to you, I’d suggest you to generate your getters and setters, or simply use Snippet in CFEclipse or CF Builder.
In the order of most efficient to least efficient:
CF9 implicit getter/setter > getter/setter function > CF8 onMissingMethod()
I usually use cfscript for getting and setters, then if I happen to upgrade to CF9, i just set accessors=true and delete the getter/setter cfscript block. Just have to make sure you use variables scope instead of variables.instance.