Lots of other answers here, but I would say take a look at your model
and what you are trying to accomplish. From the looks of it you have a
start on a DAO (Data Access Object) Among other things, the DAO is
grabbing instance data about a product. The whole purpose of the DAO is
to talk to the database either to retrieve, insert, update or delete a
row of data. That's it.
Next I would look at creating a Product object in which to store that
instance data (or possibly an Iterating Business Object (IBO), but let's
keep it simple.) The Product Object has set and get methods to set
instance data and get instance data.
You may also need a Service Object to coordinate between other objects
and act as the public API which may springboard you into creating a
factory object which seems like overkill at first but you will see the
benefits in time.
Anyway, working together it would look something like this:
thisProduct = ProductService.getProduct(productId); // Returns a
populated product object
writeOutput(thisProduct.getDescription()); // outputs the description of
the product
ProductService would contain the DAO as a variable scoped property, so
getProduct would look like:
product = variables.objectFactory.get('Prodcut') // objectFactory
creates transient objects
product.setInstanceData(variables.dao.getProd(prodId)); // How you do
this really depends. This is pseudocode for brevity's sake
return product;
I would say take a look around at some sample applications out there go
to RIAForge and see if there's anything that looks interesting and
approachable and start digging. Also there are plenty of blogs and
books and articles out there. You're on your way, but it will take
coding an application or two before it starts to click. Keep at it and
keep learning! You'll get it sooner than you think. Next you'll be
wondering how you ever did anything without OO and solid frameworks to
back it up...
anthony
-----Original Message-----
From: [email protected] [mailto:[EMAIL PROTECTED] On Behalf
Of Kevin
Sent: Tuesday, October 16, 2007 2:34 PM
To: [email protected]
Subject: [CFCDEV] scoping variables in cfc's
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
-~----------~----~----~----~------~----~------~--~---