On Thursday, Jan 30, 2003, at 07:17 US/Pacific, webguy wrote:
> Look at Seans excellent rules ..
> http://www.corfield.org/coldfusion/codingStandards.htm

Thanx. Yes, I highly recommend you use getter/setter methods. Ray gave 
a good reason but wasn't specific. Here's some more detail:

It may be a simple property today but in the future it might be 
calculated or it might be refactored into another CFC: using getter / 
setter methods means your changes will be localized (you only have to 
change the CFC, not all the code that uses it).

It may be a simple property today but in the future, you might want to 
apply validation when you set it (e.g., an age should be a positive 
integer). You can add validation logic to the setter - without changing 
code that uses the CFC.

Furthermore, you want to use the unnamed scope for your instance data 
(and this seems to be a popular idiom):

        <!--- person.cfc --->
        <cfcomponent>
                <!--- create a single 'handle' for your instance data: --->
                <cfset instance = structNew()>
                <!--- setter: --->
                <cffunction name="setFirstName" returntype="person">
                        <cfargument name="firstName" type="string" required="true">
                        <cfset instance.firstName = arguments.firstName>
                        <cfreturn this>
                </cffunction>
                <!--- getter: --->
                <cffunction name="getFirstName" returntype="string">
                        <cfreturn instance.firstName>
                </cffunction>
        </cfcomponent>

Some people have their setter functions return the object (as above), 
others prefer to return nothing - like this:

                <cffunction name="setFirstName" returntype="void">
                        <cfargument name="firstName" type="string" required="true">
                        <cfset instance.firstName = arguments.firstName>
                </cffunction>

I prefer the former since you can then "chain" method calls in cfscript:

        <cfscript>
                me = createObject("component","person");
                me.setFirstName("Sean").setLastName("Corfield");
        </cfscript>

With the latter style of function definition, you have to say:

        <cfscript>
                me = createObject("component","person");
                me.setFirstName("Sean");
                me.setLastName("Corfield");
        </cfscript>

Sean A Corfield -- Director, Architecture
Web Technology Group -- Macromedia, Inc.
tel: (415) 252-2287 -- cell: (415) 717-8473
aim/iChat: seancorfield -- http://www.macromedia.com
An Architect's View -- http://www.macromedia.com/go/arch_blog

ColdFusion MX and JRun 4 now available for Mac OS X!
http://www.macromedia.com/go/cfmxosx

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
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
Your ad could be here. Monies from ads go to support these lists and provide more 
resources for the community. http://www.fusionauthority.com/ads.cfm

                                Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
                                

Reply via email to