This looks like SomeComponent extends BaseComponent which allows the API
to accept set('someProperty',someValue) and invoke setSomeProperty in
the extended component.If setSomeProperty exists in someComponent it is invoked else set just sets the value in variables.instance. setSomeProperty needs to be defined in the child component, but you still call set() for all components. I think this is more useful for getters that do transformations on the properties(e.g. getTime() which takes a datetime property and only returns the time, possibly formatted to a standard.) I don't see much advantage for setters. If I'm understanding the question/thread this is the opposite of what you are asking for because you still have to define the setSomeProperty in SomeComponent. That is, you HAVE to define a method somewhere, they are never dynamically constructed. anthony -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Aaron Roberson Sent: Friday, May 04, 2007 9:57 AM To: [email protected] Subject: Re: [CFCDEV] baseComponent.cfc Yes Peter, purely syntactic sugar. However, I think that syntax is just as important to you as it is to me :) Just so that we are all on the same page, here is the methods from Hal's baseComponent.cfc class: <cffunction name="set" access="public" output="false"> <cfargument name="propertyName" required="true" /> <cfargument name="propertyValue" required="true" /> <cfif StructKeyExists(this, 'set' & arguments.propertyName)> <cfinvoke component="#this#" method="set#PropertyName#"> <cfinvokeargument name="propertyName" value="#arguments.propertyName#" /> <cfinvokeargument name="propertyValue" value="#arguments.propertyValue#" /> </cfinvoke> <cfreturn /> </cfif> <cfset variables.instance[arguments.propertyName] = arguments.propertyValue /> </cffunction> <cffunction name="get" access="public" output="false" hint="Throws exception if variables.instance[propertyName] not found"> <cfargument name="propertyName" required="true" /> <cfset var results = variables.instance[arguments.propertyName] /> <cfif StructKeyExists(this, 'get' & arguments.propertyName)> <cfinvoke component="#this#" method="get#arguments.propertyName#" returnvariable="results" /> </cfif> <cfreturn results /> </cffunction> As you can see, the set method checks to see if set#arguments.propertyName# exists and if it does it invokes it. Is this checking if a method named set#arguments.propertyName# exists in the child method or in the base component? The reference to this has me thinking it could be the latter (and then I searched to find out, got more confused, posted this thread, and you know the rest), but what do I know? Thanks, Aaron On 5/4/07, Peter Bell <[EMAIL PROTECTED]> wrote: > Hi Aaron, > > If you're talking about a method called getProperty(), of course you > could rename your generic getter to getProperty() and that would work. > I'm assuming you're more talking about a get#PropertyName#() solution > so you could call getFirstName() an getLastName() without actually > having to write such methods. > > To my knowledge there is no way you can implement this in ColdFusion > as you are calling methods that don't exist. To be able to do this you > would need some kind of missing method handler capability in CF which > would then effectively take care of this problem. > > Only thing I'd say is that to me this is more syntactic sugar than > anything else - the difference betweeen getUserName() and > get("UserName") is to me fairly subtle. > > Best Wishes, > Peter You are subscribed to cfcdev. To unsubscribe, please follow the instructions at http://www.cfczone.org/listserv.cfm CFCDev is supported by: Katapult Media, Inc. We are cool code geeks looking for fun projects to rock! www.katapultmedia.com An archive of the CFCDev list is available at www.mail-archive.com/[email protected] You are subscribed to cfcdev. To unsubscribe, please follow the instructions at http://www.cfczone.org/listserv.cfm CFCDev is supported by: Katapult Media, Inc. We are cool code geeks looking for fun projects to rock! www.katapultmedia.com An archive of the CFCDev list is available at www.mail-archive.com/[email protected]
