I would (and do) pass the datasource name to every method call.
Alternatively, you could create an instance variable inside the component that contains the datasource name, but I don't know if I would recommend that; because you'd likely have an instance variable for every component, which may make it hard to maintain.
At 09:19 PM 9/29/2004, you wrote:
I have a practical question to bring to this little discussion.
I am currently coding my first site which makes large-scale (for me) use of CFCs. Most of these CFCs access the database for the site. I am currently using a request variable to store the datasource. I am not doing this because I don't believe in the value of encapsulation, but rather because I can't figure out a better way to handle it.
I don't want to pass the datasource in to each and every method. I don't want to incur a bunch of overhead in getting the datasource for query in every method. I do want to be able to invoke some methods (via cfinvoke) without first instantiating the object.
I am certainly missing some good practice of which others are aware. I would love to be enlightened.
Thanks All!
Steve
At 07:35 PM 9/29/2004, you wrote:You are, of course, free to do whatever you like. But encapsulation has a huge history of benefits and I'm afraid your opinion isn't going to put the slightest dent in that history.
In your example, I would argue that you should indeed be passing the CGI variable into the CFC and not calling it directly. There's absolutely no reason to do call it directly, the "cost" of passing it in is miniscule, but the benefits of well-encapsulated code are thoroughly confirmed. The same applies to calling request-scoped UDF's from within a CFC: it's totally unnecessary. In fact, why are the UDF's in the request scope anyway? I'd say, move them into an object and call them through the object. If another CFC needs to use them, I'll pass in the object.
----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email
to [EMAIL PROTECTED] with the words '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]
--
Jeffry Houser, Web Developer, Writer, Songwriter, Recording Engineer
<mailto:[EMAIL PROTECTED]>
--
AIM: Reboog711 | Phone: 1-203-379-0773
--
My Books: <http://www.instantcoldfusion.com>
Recording Music: <http://www.fcfstudios.com>
Original Energetic Acoustic Rock: <http://www.farcryfly.com>
--
When did Reality Become TV
----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email
to [EMAIL PROTECTED] with the words '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]
