> I'm just starting to write my first CFC in anger, as it
> were, and was curious
> about what others were doing.
> Are people writing a number of of
> getX,getY,getName,get.... methods, each
> returning a string/numer and then using
> <cfobject component="com.locavista.location"
>       name="objLocation">
> <cfoutput>#objLocation.getName(156537)#</cfoutput>
> OR writing a single get that returns a query or custom
> object, and then using
> <cfinvoke component="com.locavista.location"
>       method="get"
>       iLocId="156537"
>       returnVariable="objLocation" >
> <cfoutput>#objLocation.description#</cfoutput>

> Obviously, no difference in output, but writing lots of
> get'ers is time
> consuming, though provides better abstraction from the
> datastore.
> Also, each getX will make a database query, so outputting
> a list of the
> objects will be much slower using the first method than
> the second, as I see
> it.

> So I'm plumbing for doing it the 2nd way - is there any
> sort of consensous on
> this ?

Not that I've worked with CFC's as of yet, but there is a 3rd way.

Write a single pair of set / get functions into a "core" cfc and then have
all your other cfc's extend the core cfc, so that for any given component
you know that you can use #mycfc.getValue("propertyname")# to return
whatever that property happens to be whether it's a string, struct, array or
another CFC. For any property which needs special handling, write an
additional get / set method, then in the core get / set method check for the
existance of a get or set method specifically for that property, such as:

<cffunction name="getValue" ouptut="false">
  <cfargument name="propertyname" type="string" required="true">

  <cfif isdefined("this.get_" & propertyname)>
    <cfreturn evaluate("this.get_#propertyname#()")>
  <cfelse>
    <cfreturn this[propertyname]>
  </cfif>
</cffunction>

And of course, use a similar set function. This way you only have to write
getters and setters for properties that require special internal handling by
the CFC for business logic or technical reasons.

Ahhh the magic of OO. :)

s. isaac dealey                954-776-0046

new epoch                      http://www.turnkey.to

lead architect, tapestry cms   http://products.turnkey.to

tapestry api is opensource     http://www.turnkey.to/tapi

certified advanced coldfusion 5 developer
http://www.macromedia.com/v1/handlers/index.cfm?ID=21816

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
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
This list and all House of Fusion resources hosted by CFHosting.com. The place for 
dependable ColdFusion Hosting.

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

Reply via email to