ColdFusion Singletons

Singletons are perhaps one of the most simple Design Patterns. For those who don't know sigletons are a class that can only have one instance. They can be thought of as a glorified global variable - but are a lot more useful.

Most ColdFusion classes, or rather instances of CF components, can be turned in a singleton by placing the following code in your Application.cfm:

<cfif not structkeyexists(application,<instance name>)>
      <cfset application.<instance name> = createobject("component",<path to component>)>
   </cfif>

or OnApplicationStart method of your Application.cfc:

<cfset application.<instance name> = createobject("component",<path to component>)>

[More]