> -----Original Message----- > From: Rick Faircloth [mailto:[EMAIL PROTECTED] > Sent: Wednesday, October 22, 2008 10:10 AM > To: cf-talk > Subject: How can this CFC be improved? > > Hi, all... still trying to get a handle on using CFC's. > > Here's an update method I wrote and I'd like to know > what can be changed to make it better. Such as, > why not use the form scope in the query? And, why > not just use the application scope for the dsn, instead > of converting it to the variables scope?
I don't see anything "wrong" with that per se. However I've sometimes found it more versatile to parametize such things: in the best case you'll be using your CFCs again in other sites (portability of OO) and knowing what they need and being able to control it without modifying the CFC is sometimes a life-saver. > If components have access to the url, form, session, and > application scopes, etc., why not use them in the component? > What's the benefit of converting them? In general OO "likes" to be encapsulated - the information used by an object should be clearly passed in and out. Of course there are millions of exceptions, but that's the rule of thumb. One comment at least in this code: it seems like you're creating the query in the CFC variables scope (by not creating the query name first with "var"). This makes it available outside of the CFC but also makes the CFC less self-documenting. As with the input side being explicit about the output side is also generally desirable: in this case making the query variable a function-local variable (using "var") and passing the result explicitly out using "return". More importantly however: this could cause data corruption depending on how you instantiate this CFC. For example if you make this CFC persistent (store it in the Session, Application or Server scopes) you might get a situation where two requests call the same method. If that happens the methods themselves will be isolated but the "public" variable they BOTH write too is not. If they both run at the same time you could very easily end up with data from one thread ending up in the other. Not good. Jim Davis ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to date Get the Free Trial http://ad.doubleclick.net/clk;207172674;29440083;f Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:314225 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4