I have a question on the subject of Singletons, opinions solicited. Allow me to 
illustrate my question by comparing what I consider to be two nearly equivalent 
means of executing the Singleton pattern:

scenario A (the object written exactly right):

<!-- create the singleton.... -->
<cfset application.objUtilities = createobject("cfc","model.utilities") />

<!-- utilize the singleton... -->
<cfset myResults = application.objUtilities.getResults() />


Scenario B (the object written questionably):

<!-- create the singleton.... -->
<cfset application.objUtilities = createobject("cfc","model.utilities") />
 
<!-- utilize the singleton... -->
<cflock name="getresults" timeout="10" throwontimeout="no" type="exclusive">
    <cfset myResults = application.objUtilities.getResults() />
</cflock>


At times, writing a CFC that is to be utilized as a singleton can be a bit 
tricky for me...trying to visualize it being accessed by multiple users 
simultaneously leaves me thinking that maybe there's something I overlooked. 
So, it occurred to me to simply wrap my singleton call in a cflock tag, then 
there's no doubt at all that my singleton calls won't be stepping on each 
other's toes.

So the question is, first of all, how does wrapping an object call in cflock 
tags strike you as a developer? Does it seem hacky or otherwise unsettling? 
Secondly, can a cfc (generally speaking) act as a singleton if we do wrap it in 
an exclusive lock like that? Of course I know that a lot of the answer depends 
upon how the CFC is written, but assuming the object isn't persisting values 
between calls, would you consider something like this acceptable, or is it far 
far from best practice?
Lastly, can anybody offer or point me to some resources that provide good solid 
guidelines to follow when writing a CFC that is to be utilized as a Singleton?

Thanks!
Doug B 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to 
date
Get the Free Trial
http://ad.doubleclick.net/clk;203748912;27390454;j

Archive: 
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:308906
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4

Reply via email to