As you get a little further down the path of learning CFCs and OOP, you'll
probably shy away from this kind of setup anyway. A typical approach to
something like this is to populate an object that represents a single
Product and return that. Then, you'd have no need to have a separate method
for getDescription() here, and no need to run the whole query every time you
want to get a single attribute of a Product (like the description or
anything else). Instead, you might do:

product = productService.getProduct(1);

The product service would run the query to get the data for the specified
product, then use the query data to populate an instance of a Product object
that holds data and behavior related to a single, concrete product. Finally
it would return that Product object.  Then you can do:

product.getDescription();
product.getName();
product.getDiscountedPrice();
etc.

(side note: Having an object that this which uses getters and setters for
its properties is known as a "Bean", which is a term that came from the Java
world.)

On 10/16/07, Kevin <[EMAIL PROTECTED]> wrote:
>
>
> I have been trying to teach myself cfc's and I am having trouble
> understanding this.
>
> I know you should var scope any variables that are available only to
> the instance in a call to a method.
>
> But should they always be scoped locally?
> eg.
>
> I have a function in a products.cfc
>
> <cffunction name="getdetail" access="public" returntype="query">
>     <cfargument name="item" default="" required="yes" type="numeric" />
>      <cfset qry_detail = "">
>     <cfquery name="qry_detail" datasource="#variables.datasource#">
>   SELECT TITLE, DESCRIPTION FROM mytable WHERE item = <cfqueryparam
> cfsqltype="cf_sql_integer" value="#arguments.item#" />
>    </cfquery>
> </cffunction>
>
> I have another function in the same cfc that uses the query to get a
> field if it has a value.
>
> <cffunction name="getdescription">
> <cfif len(qry_detail.DESCRIPTION) and qry_detail.DESCRIPTION neq 0>
>   <cfreturn qry_detail.DESCRIPTION>
> </cfif>
> </cffunction>
>
> And i just call it in the .cfm with #products.getdescription()#.
>
> Now I have been reading that if the var scope is not used on the
> query, a race condition can happen.
>
> But if I use
> <cfset var qry_detail = "">
> qry_detail.DESCRIPTION is not available to the getdescription function.
>
> Can a query used like this cause a race condition? Or should I redo
> the functions to contain the query only within var scope the cfc?
>
> Thanks ahead.
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CFCDev" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cfcdev?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to