My co-worker is making a shopping cart, trying to keep it fairly CFC oriented, not necessarily OO to the core, just reliant on CFCs in places where they would seem useful.
Anyway, we got into a discussion about his cfscript library, which he turned into a CFC for portability. Now he'd like to use that object in all of his other CFCs, some scoped to session, some to application, some to single page requests, etc.
I'm no OO pro, but in Java, we would use the "import" keyword (or "using" for c sharpies out there). What's the best way to do this through a CFC?
1) instantiate the cfscript cfc in each component 2) instantiate the cfscript cfc in the application, call application.cfscript.method() - doesn't sound good, i know, but i'm just throwing it out there. 3) instantiate the cfscript cfc in the application, pass the reference in as an argument on init() 4) any other ideas?
Barney Boisvert 23 August 2004 23:24:12 [ permanent link ]
If the methods are static, use CFINVOKE on the component, rather than an instance. If they're not static (or you want to call them non-statically for performance reasons), then I'd instantiate the class in the constructor of each CFC that uses it and keep it around in an instance variable. Depending on your situation, it might make more sense to instantiate per method call, if you're going to be creating a lot of instances of the calling object, but most of them won't be using the utility class.
Whether you're using the external CFC is an implementation detail, so it shouldn't be dependant on the environment (app var or an init param), at least in my view.
cheers, barneyb
On Mon, 23 Aug 2004 13:03:38 -0700, Nathan Strutz <nathans-C/evCYVThEZBDgjK7y7TUQ@public.gmane.org> wrote:> My co-worker is making a shopping cart, trying to keep it fairly CFC> oriented, not necessarily OO to the core, just reliant on CFCs in places> where they would seem useful.>
Anyway, we got into a discussion about his cfscript library, which he> turned into a CFC for portability. Now he'd like to use that object in> all of his other CFCs, some scoped to session, some to application, some> to single page requests, etc.>
I'm no OO pro, but in Java, we would use the "import" keyword (or> "using" for c sharpies out there). What's the best way to do this> through a CFC?>
1) instantiate the cfscript cfc in each component> 2) instantiate the cfscript cfc in the application, call> application.cfscript.method() - doesn't sound good, i know, but i'm just> throwing it out there.> 3) instantiate the cfscript cfc in the application, pass the reference> in as an argument on init()> 4) any other ideas?>