> Any chance of cfc's implementing built in set/get methods on
> properties, like c# and the javabean framework?
I like this idea. Why wait for a future version?
If you don't need your setters and getters to do anything more than
just set and get properties (without modifying those properties), you
might be able to save yourself the hassle of implementing all those set
and get functions by building a little support framework. In the
example below, there is a component called "support.cfc" which all
components that need a lot of get and set methods should extend.
Notice how the component "test_support.cfc" is free to set and get
arbitrary properties without those set and get methods actually having
been implemented. (This will also hold true if your component contains
an instance of a component that extends support as opposed to extending
support itself as in the example below.) I believe you can even scope
variables (with or without "this") using this technique:
support.cfc
<cfcomponent>
<cffunction name="setter" access="public">
<cfargument name="varName" type="string" required="yes" />
<cfargument name="varValue" required="yes" />
<cfscript>
setVariable(varName, varValue);
</cfscript>
</cffunction>
<cffunction name="getter" access="public">
<cfargument name="varName" type="string" required="yes" />
<cfreturn evaluate(varName) />
</cffunction>
</cfcomponent>
support_test.cfc
<cfcomponent extends="com.macromedia.util.support">
<cffunction name="init" access="remote">
<cfinvoke method="setter" varName="this.foo" varValue="bar" />
<cfinvoke method="getter" varName="this.foo"
returnVariable="baz" />
<cflog text="#baz#" />
</cffunction>
</cfcomponent>
I'm sure there are better ways to implement this type of technique, but
you get the idea.
Christian
> --
> jon
> mailto:[EMAIL PROTECTED]
>
> Thursday, January 30, 2003, 12:19:23 PM, you wrote:
> SAC> On Thursday, Jan 30, 2003, at 07:17 US/Pacific, webguy wrote:
>>> Look at Seans excellent rules ..
>>> http://www.corfield.org/coldfusion/codingStandards.htm
>
> SAC> Thanx. Yes, I highly recommend you use getter/setter methods. Ray
> gave
> SAC> a good reason but wasn't specific. Here's some more detail:
>
> SAC> It may be a simple property today but in the future it might be
> SAC> calculated or it might be refactored into another CFC: using
> getter /
> SAC> setter methods means your changes will be localized (you only
> have to
> SAC> change the CFC, not all the code that uses it).
>
> SAC> It may be a simple property today but in the future, you might
> want to
> SAC> apply validation when you set it (e.g., an age should be a
> positive
> SAC> integer). You can add validation logic to the setter - without
> changing
> SAC> code that uses the CFC.
>
>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Archives: http://www.houseoffusion.com/cf_lists/index.cfm?forumid=4
Subscription:
http://www.houseoffusion.com/cf_lists/index.cfm?method=subscribe&forumid=4
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
Get the mailserver that powers this list at http://www.coolfusion.com
Unsubscribe:
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4