Personally, I think of UDFs and CFCs as quite distinct, though I'll often
store my "global" UDFs in the application scope in a struct called "UDF" --
that way in my code I can call:

application.udf.myFunction()

In my Application.cfm file, as part of the initialization of my application
I call a page that has all my UDFs as a CFMODULE call, and inside that it
loops through the VARIABLES scope and places any UDFs (found using
isCustomFunction) in the application.udf struct -- since that happens only
once when the application initializes, from then on I have all my global
UDFs cached in the application scope.  In the end, I don't think it's much
different than putting them all in a CFC, so you are probably OK at that
level.

However, from the perspective of "OO" design, extending that CFC everywhere
is actually a practice generally considered a bad idea -- the "best
practice" is to use extends only when you are expressing an "is a"
relationship -- not just to reuse code across components.  If you wanted to
be a bit cleaner about it, but still use your single CFC to hold "global
functions", you could instantiate your global CFC inside your other
components, and/or pass your global CFC into your other components as part
of their "init".

In addition to painting yourself into a corner from a design standpoint, you
are also adding non-trivial overhead to all of your CFC instantiations by
extending another heavy CFC -- that will be a particular problem if you
aren't caching most of your CFCs globally when you use them.




> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
> Behalf Of Ian Sheridan
> Sent: Tuesday, June 01, 2004 7:38 AM
> To: [EMAIL PROTECTED]
> Subject: Re: [CFCDev] UDF in a CFC or Include?
>
>
> Well I placed all my UDFs in a central CFC that all my other CFCs
> extend. This practice makes sense to me but I do not know if it is the
> best way to go about it.
>
>
> On Jun 1, 2004, at 10:22 AM, Dawson, Michael wrote:
>
> > If possible, I would put the functions in a CFC, then store the CFC in
> > the Application scope.  That would keep them in memory.
> >
> > If you have other CFCs that might use the UDF CFC, you can pass a
> > reference to the necessary methods.
> >
> > <cfset Application.Functions = CreateObject("component", "UDFs")>
> >
> > ...then...
> >
> > <cfset myReturnVar = myMethod(Application.Functions, "myOtherArg")>
> >
> > M!ke
>
> ----------------------------------------------------------
> 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]
>

----------------------------------------------------------
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]

Reply via email to