Hal Helms uses the same style of coding you're talking about. A master get/set 
method where you pass in the value AND name of the property you're trying to 
access.

andy

-----Original Message-----
From: Peterson, Chris [mailto:[EMAIL PROTECTED] 
Sent: Monday, July 09, 2007 2:52 PM
To: CF-Talk
Subject: Init method and getters / setters in cfc

A lot of cfc's using init and 'good' OO practices have functions like getDSN(), 
setDSN('Blah') littered throughout. Can I ask any guru out there why you 
wouldn't use simple get('keyname') and
set('keyname','keyvalue') like the following?

        <cffunction name="get" access="public" output="no"
returntype="any">
                <cfargument name="name" required="true" type="string">
                <cfreturn evaluate('variables.' & arguments.name) />
        </cffunction>

        <cffunction name="set" access="public" output="no"
returntype="void">
                <cfargument name="name" required="true" type="string">
                <cfargument name="value" required="true" type="any">
                <cfset variables[arguments.name] = arguments.value />
        </cffunction>

Then instead of littering your cfc with numerous getters / setter, you have 2 
methods that should be able to handle simple or complex values without any 
problems with much less code.


Chris Peterson
Gainey IT
Adobe Certified Advanced Coldfusion Developer



~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
CF 8 – Scorpio beta now available, 
easily build great internet experiences – Try it now on Labs
http://www.adobe.com/cfusion/entitlement/index.cfm?e=labs_adobecf8_beta

Archive: 
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:283311
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4

Reply via email to