As we all know, there are may more ways to skin a cat, here is my version of a CFC that wraps a table. I'm in the process of writing a page that looks at a table and writes this code for me. So, I too am looking for a code critique.
First off, use 'variables' scope, not 'this' scope.
Second, avoid dependencies on your environment:
<cfquery name="qryThisRecord" datasource="#request.lp.dsSQL#">
Either pass the datasource in to the function or at initialization or, in the worst case, create a known CFC that acts as an information service for your application that has a method that returns the DSN.
returnThis =
createObject('component','inetcfc.shipping.Service');
returnThis.setData(qryThisRecord,1);
Third, while this approach - converting a query row to an object - is reasonable when you are after a specific object from the database, it doesn't scale well to aggregate data like you have here:
for(q=1; q lte qryRecords.recordCount; q=q+1){
arrayAppend(returnArray,createObject('component','inetcfc.shipping.Serv ice'));
returnArray[q].setData(qryRecords,q);
}
If you are dealing with aggregate data, use a query object and only convert rows to objects if you really need the object behavior itself. A good example is a master-detail editing application. The master list just shows selected aggregate data - you don't need objects for that, a query object will be just fine. When you drill down into the detail page, you're dealing with a single object and likely need the behaviors of that object.
This is all about picking the right level of abstraction for what you're doing and thinking about whether you're interested in the *object* itself or just in certain aspects of *aggregate data*...
If you load 100 records and convert them all to objects, that's a lot of object creation and, more importantly, a lot of data being copied around. One of the keys to high-performance apps is deferring work - see this blog entry about a JavaOne session:
http://www.corfield.org/ index.php?fuseaction=blog.archive&month=2003_06#000398
Sean A Corfield -- http://www.corfield.org/blog/
"If you're not annoying somebody, you're not really alive." -- Margaret Atwood
----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email
to [EMAIL PROTECTED] with the word 'unsubscribe cfcdev' in the message of the email.
CFCDev is run by CFCZone (www.cfczone.org) and supported by Mindtool, Corporation (www.mindtool.com).
An archive of the CFCDev list is available at www.mail-archive.com/[EMAIL PROTECTED]
