That would be cool except for sometimes the init() function needs to be
called after some assignments. Consider the following example
<cfset server.myVar = createObject("component","foo")/>
<cfset server.thing = handleToSomething>
<cfset server.startupip = "192.168.1.11">
<cfset server.init()/>
if "thing" and "startupip" had resources that the object needed, and the
init() was called without those being assigned, the object could blowup.
-----Original Message-----
From: S. Isaac Dealey [mailto:info@;turnkey.to]
Sent: Friday, November 01, 2002 12:54 PM
To: CF-Talk
Subject: RE: Understanding Locking In CFMX
> No, it says you have to think about whether you need to lock or not,
> just like in other languages. Consider this construct:
> <cfif isDefined("server.myVar")>
> <cfset server.myVar = createObject("component","foo")/>
> <cfset server.init()/>
> </cfif>
> If this can be executed by multiple requests simultaneously, you need
> to lock it. Where do you need the lock? Just around the update? No, in
> this case you need the lock around the whole <cfif.../> tag. Why?
> Consider this (bogus) code:
> <cfif isDefined("server.myVar")>
> <cflock name="server_myVar" type="exclusive">
> <cfset server.myVar = createObject("component","foo")/>
> <cfset server.myVar.init()/>
> </cflock>
> </cfif>
I'm curious. Can anyone explain to me why createObject() isn't enough to
instantiate the object? I mean, why it is that <cfset server.myVar.init()/>
would even be required here? It seems to me like the init() could just as
well be an assumed part of a constructor for the object/cfc/etc... And
better still because it would be less code and less prone to screw-ups that
way.
S. Isaac Dealey
Certified Advanced ColdFusion 5 Developer
www.turnkey.to
954-776-0046
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Archives: http://www.houseoffusion.com/cf_lists/index.cfm?forumid=4
Subscription:
http://www.houseoffusion.com/cf_lists/index.cfm?method=subscribe&forumid=4
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
Structure your ColdFusion code with Fusebox. Get the official book at
http://www.fusionauthority.com/bkinfo.cfm