implicit getters and setters using CF

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>