On Thursday, Oct 31, 2002, at 03:51 US/Pacific, Douglas Humphris wrote:
Do you think there would be a case for using a CFC for storing global constants. Perhaps creating a controller CFC which exposes the global vars and returning a struct which can be set in request...
Even with several variables, I'd probably still lean toward simply setting them in request scope (as the initial post below commented).

Alternatively, create a config CFC and create an instance in application scope (or server scope) but instead of getting all the globals as you suggest, have a separate method call for each global - and have the CFC initialize itself 'on demand'. This means the overhead for initialization is lower per page and the cost is only incurred at usage - following the C++ principle of only paying for what you use.

Application.cfm:
<cflock type="exclusive" name="myAppGlobals">
<cfif not isDefined("server.myAppGlobals")>
<cfset server.myAppGlobals = createObject( "component", "config.globals" )/>
</cfif>
</cflock>

Then each use would change from (in your code):

request.strConfig.aGlobalValue

to:

server.myAppGlobals.aGlobalValue()

The CFC would look like:

config/globals.cfc:
<cfcomponent>
<cffunction name="aGlobalValue" ...>
<cfreturn someValue/>
</cffunction>
</cfcomponent>

That's an approach I've used successfully in C++ and Java. The globals component would usually have an init() method that reads the values from a config file (XML perhaps) and initializes an internal struct so in reality, each method would look like:

<cffunction name="aGlobalValue" ...>
<cfset init()/>
<cfreturn myConfig.aGlobalValue/>
</cffunction>

init() would read the data into a private struct (myConfig) on first execution only.

My gut feeling is to follow Sean Corfield's best practices
recommendation:
http://www.corfield.org/coldfusion/codingStandards.htm#Anchor34
Sean A Corfield -- http://www.corfield.org/blog/

"If you're not annoying somebody, you're not really alive."
-- Margaret Atwood


--
** Archive: http://www.mail-archive.com/dev%40lists.cfdeveloper.co.uk/

To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
For human help, e-mail: [EMAIL PROTECTED]

Reply via email to