As promised, here are the slides and code examples for my CF.Objective() 2008 presentation. Feel free to post any comments or questions and I'll get to them asap.

As I mentioned after the presentation, I'm also going to be putting together an intermediate version of this talk covering more complex patterns. Also, I have been told that CF.Objective() 2009 will be tentatively scheduled for May 6-9. So now you have plenty of time to begin schmoozing your bosses to let you go. I have to say that this is THE conference for learning the high level skills needed to build enterprise level applications in ColdFusion.


Here's the link to download the presentation and code examples:

Leveraging_Basic_Design_Patterns_in_ColdFusion

CF.Objective() - Done Presenting

I'm done with my presentations on "Leveraging Basic Design Patterns in ColdFusion" talk at CF.Objective(). For those of you who attended, thank you very much for coming! I hope you have learned something useful that will help make your day to day coding better, and I'd love to hear from you on any feedback. I will be posting my slides and code examples as soon as I return home to Maryland. Also, I am thinking about making an extension to this intro talk with an intermediate session covering more patterns, let me know if you are interested in that as well.

I'd like to also thank our great hosts Jared Rypka-Hauer, Steven Hauer and Jim Louis for a great conference experience, both as a speaker and as an attendee. I'm looking forward to CF.Objective() 2009!

Capital Area Flex User's Group April Meeting Reminder

Just a quick meeting reminder that the Capital Area Flex User's Group is meeting this Wednesday night at 6:30pm at AboutWeb.

We have another amazing meeting lined up for you tomorrow night. To start off the night we'll have Ashish Jaiman from Microsoft present on Silverlight. This should be an opportunity to see where Microsoft stands with it's competing product and perhaps inspire some friendly rivalry.

After a break for food and drinks, Kelly Brown will be presenting on BlazeDS, an open source Flex/Air server initiative from Adobe.

Please arrive by 6:30pm at our Rockville office as presentations will begin promptly at 7:00pm. For directions and more information visit www.dc-flex.org.

As always, we will be broadcasting the event live on Adobe Connect. To follow the event online (sorry no e-food though!) go to http://adobechats.adobe.acrobat.com/capfug0408/.

Capital Area Flex User's Group Meeting Reminder

Just a quick meeting reminder that the Capital Area Flex User's Group is meeting tonight at 6:00pm to celebrate the much anticipated launch of Adobe Flex 3.0 and AIR 1.0!

Adobe's RIA technologies enable you to rapidly build and deploy the most engaging applications across browsers and on the desktop. The DC Flex Usergroup is hosting a special live event to share exciting new information on Adobe's platform tools and technologies for building RIAs. You'll see an exclusive user group video presentation by Adobe Chief Software Architect, Kevin Lynch, hear some important product news, plus get your hands on some exclusive schwag and other giveaways. Be part of the fun and excitement and join the rest of the Adobe developer community by participating in this very special event

As always, we will be broadcasting the event live on Adobe Connect. To follow the event online (sorry no e-food though!) go to http://adobechats.adobe.acrobat.com/capfug0308/.

Flex Camp Washington, DC 2008

Just want to pass on the word that tomorrow AboutWeb LLC and Adobe Systems will be hosting the Flex Camp Washington, DC 2008. This is one-day gathering with Adobe Flex experts covering everything you need to know about the power of Flex, the upcoming release of Flex 3, and a bit about the much anticipated Adobe Air.

Since we have already surpassed the registration capacity, we are going to be broadcasting the entire event live on Adobe Connect from 9:30am to 12:00pm and then after lunch break from 1:00pm to 5:00pm (All times are Eastern Standard Time).

To view the event go to http://adobechats.adobe.acrobat.com/dcflexcamp08/, choose the "Enter as a Guest" option and click "Enter Room" after entering your name. We look forward to seeing you online!

Presenting at CFUnited 2008.

I just received confirmation that I will be giving two presentations at CFUnited 2008.

The first is "Integrated ColdFusion Development Environment" which will cover the use of CFEclipse along with version control (using Subversion) and automated build scripts (using ANT) to help organize, maintain and simplify you and your development team's day to day tasks.

The second is "Leveraging Basic Object-Oriented Concepts in ColdFusion". This presentation's focus is to give the basic knowledge necessary to those programmers wanting to venture into using object oriented programming techniques in ColdFusion. If you have been waiting to make the move into OO, but were not sure where to start, this is the presentation for you.

Also, don't forget that Early Bird Registration prices end this Friday, November 30th!

For a more detailed summary about both topics:

Integrated ColdFusion Development Environment

Leveraging Basic Object Oriented Concepts in ColdFusion

Capital Area Flex User Group - November 07 Recorded Session

As mentioned previously we have started to broadcast live and record the Capital Area Flex User Group meetings. Last night we had a great turnout and special thanks to Danny Dura and Christian Cantrell for coming out and presenting.

Here are the recorded sessions:

Danny Dura, Adobe Evangelist
Adobe AIR Overview
http://adobechats.adobe.acrobat.com/p26954584/

Christian Cantrell, AIR Product Manager
Deconstructing AIR Applications
http://adobechats.adobe.acrobat.com/p41045993/

Capital Area Flex User's Group - Now Broadcasting Live!

Just want to quickly mention that tonight's CAPFug meeting will be the first of many that will be broadcast live using Adobe Connect.

Tonight's meeting with our special guest speakers from Adobe can be seen here:

http://adobechats.adobe.acrobat.com/capfug1107

Capital Area Flex User's Group - A breath of fresh AIR!

Just a quick note that tomorrow evening, Wednesday, November 7th, the Capital Area Flex User's Group(CAPFug) will be hosting two special guest speakers from Adobe.

Danny Dura, Adobe Evangelist, will be giving an overview of Adobe AIR and Christian Cantrell, AIR Product Manager, will dive into some details with "Deconstructing AIR Applications".

The meeting will start shortly after 6:00pm here at the AboutWeb Office and as always, free pizza, sodas and snacks are provided during the social break between sessions.


Capital Area Flex User's Group(CAPFug)
AboutWeb Office
6177 Executive Blvd
Rockville, MD 20852
(301) 468-9246

ObjectFactory Explained

In my previous post, I posted some code from the CentralPA CFUG presentation that Scott Stroz and I used. It used an ObjectFactory.cfc file that I had created prior to the presentation and am kicking myself for not doing/using this earlier. Now you're probably saying to yourself... "Another ObjectFactory!!!". Yes, this one I hope will prove to have its uses.

First, a bit about objectFactories. In a nutshell, objectFactories are nothing more then an object that returns other objects given a key. Meaning once objectFactory is instantiated in the application (in our case in the Application scope as a singleton), I can simply get to any objects "known" within the objectFactory by calling it like this:

Listing 1
<cfset myObjectInstance = application.objectFactory.create("ObjectKey") />

One of the advantages to this approach is obvious, there's no need to defined the entire path to the object everytime I need to instantiate it. This comes very handy if I have to make changes to my object paths, for example while using a proxy object to wrap the original object (see Decorator Pattern). When using an objectFactory, all my object paths are all in one place and not scattered throughout my entire application. Here's an example of a regular objectFactory:

Listing 2 - ObjectFactory.cfc
<cfcomponent displayname="ObjectFactory">

<!--- constructor method --->
<cffunction name="init" access="public" returntype="ObjectFactory" output="false" hint="constructor method">
<cfreturn this />
</cffunction>

<!--- public methods --->
<cffunction name="create" access="public" returntype="Any" output="false" hint="I return an object">
<cfargument name="objectKey" type="String" required="yes" />
<cfset var object = 0 />
<cfswitch expression="#arguments.objectKey#">
<cfcase value="Registrant">
<cfset object = createObject("component","cfugDemo.com.model.registrant.Registrant") />
</cfcase>
<cfcase value="RegistrantGateway">
    <cfset object = createObject("component","cfugDemo.com.model.registrant.RegistrantGateway") />
</cfcase>
<cfcase value="Fee">
<cfset object = createObject("component","cfugDemo.com.model.fee.Fee") />
</cfcase>
<cfcase value="FeeGateway">
<cfset object = createObject("component","cfugDemo.com.model.fee.FeeGateway") />
</cfcase>
</cfswitch>
</cffunction>

</cfcomponent>

And this could be instantiated in my application as:

Listing 3 - Application.cfm
...

<!--- objectFactory - singleton --->
<cfif NOT structKeyExists(application,"objectFactory") OR url.reInit>
<cfset application.objectFactory = createObject("component","cfugDemo.com.model.objectFactory.ObjectFactory").init() />
</cfif>

...

And anytime I want to use an instance of an object I simply call it like this:

Listing 4
<!--- instantiate registrant --->
<cfset registrant = application.objectFactory.create("Registrant").init() />

As you can see the create method simply returns the appropriate object. So if I need to change the path to use a proxy object or an object that extends the object type already in my code I simply edit the ObjectFactory.cfc file.

Okay, that was a basic example of objectFactory, now why implement object oriented principles and still have to edit the ObjectFactory.cfc file everytime I want it to be able to return a new object. Isn't the reason we like CFC's because we can reuse them across our applications? Hence the improvements I made to the ObjectFactory.cfc. First, why hard code all objects in my application in the cfswitch statement if I can simply tell the ObjectFactory.cfc what objects are there on application start? By allowing me to register each object information once into my factory and store it into a Struct data type, it now can be reused and also the create method can run faster without the need to figure out which object to instantiate via the cfswitch.

Another improvement made was to be able to tell the ObjectFactory in the register method that an object is a singleton, meaning I only want that object instantiated once in my entire application and shared everytime it's requested. This is very useful for objects like DAO's, Gateways, and Config Beans. Since in ColdFusion complex objects are passed by reference, the ObjectFactory simply stores a reference to the instantiated object before it returns the object to the user. Since ObjectFactory is already being persisted in the Application scope, the singleton object is also persisted. So let's take a look at the new improved Object Factory below:

Listing 5 - ObjectFactory.cfc
<cfcomponent displayname="ObjectFactory" hint="ObjectFactory - Class Factory Object">

<!--- properties --->
<cfset variables.objectRegistry = 0 />
<cfset variables.applicationSingletons = 0 />

<!--- constructor init() method --->
<cffunction name="init" access="public" returntype="ObjectFactory" output="false" hint="initiates instance of ObjectFactory">
<cfset setObjectRegistry(structNew()) />
<cfset setSingletons(structNew()) />
<cfreturn this />
</cffunction>

<!--- getters/setters accessors methods --->
<cffunction name="getObjectRegistry" access="private" returntype="Struct" output="false" hint="gets objectRegistry property">
<cfreturn variables.objectRegistry />
</cffunction>
<cffunction name="setObjectRegistry" access="private" returntype="Void" output="false" hint="sets objectRegistry property">
<cfargument name="objectRegistry" type="Struct" required="yes" hint="value of objectRegistry" />
<cfset variables.objectRegistry = arguments.objectRegistry />
</cffunction>

<cffunction name="getSingletons" access="private" returntype="Struct" output="false" hint="gets singletons property">
<cfreturn variables.singletons />
</cffunction>
<cffunction name="setSingletons" access="private" returntype="Void" output="false" hint="sets singletons property">
<cfargument name="singletons" type="Struct" required="yes" hint="value of singletons" />
<cfset variables.singletons = arguments.singletons />
</cffunction>

<!--- public methods --->
<cffunction name="register" access="public" returntype="Void" output="false" hint="registers object information into factory">
<cfargument name="key" type="String" required="yes" hint />
<cfargument name="object" type="String" required="yes" />
<cfargument name="isSingleton" type="Boolean" required="no" default="false" />
<cfargument name="type" type="String" required="no" default="Component" />
<!--- init local var(s) --->
<cfset var registerComponent = getObjectRegistry() />
<!--- register component info --->
<cfset registerComponent[arguments.key] = structNew() />
<cfset registerComponent[arguments.key].object = arguments.object />
<cfset registerComponent[arguments.key].isSingleton = arguments.isSingleton />
<cfset registerComponent[arguments.key].type = arguments.type />
</cffunction>

<cffunction name="unregister" access="public" returntype="Void" output="false" hint="unregisters object information from factory">
<cfargument name="key" type="String" required="yes" />
<!--- if object is registered, remove it from registry --->
<cfif structKeyExists(getObjectRegistry(),arguments.key)>
<cfset structDelete(getObjectRegistry(),arguments.key) />
</cfif>
</cffunction>

<cffunction name="create" access="public" returntype="Any" output="false" hint="returns instantiated object">
<cfargument name="key" type="String" required="yes" />
<!--- init local var(s) --->
<cfset var objectRegistry = getObjectRegistry() />
<cfset var singletons = getSingletons() />
<cfset var registeredObject = 0 />
<cfset var object = 0 />
<!--- check if object is in objectRegistry --->
<cfif structKeyExists(objectRegistry,arguments.key)>
<cfset registeredObject = objectRegistry[arguments.key] />
<!--- if object was flagged as singleton and has already been instantiated get object from singleton struct --->
<cfif registeredObject.isSingleton AND structKeyExists(singletons,arguments.key)>
<cfset object = singletons[arguments.key] />
<cfelse>
<!--- instantiate new object to return --->
<cfset object = createObject("#registeredObject.type#","#registeredObject.object#") />
<!--- if new object is to be instantiated as a singleton add instance reference to applicationSingletons struct --->
<cfif registeredObject.isSingleton>
<cfset singletons[arguments.key] = object />
</cfif>
</cfif>
<cfelse>
<!--- return false if key does not exist in objectRegistry --->
<cfset object = false />
</cfif>
<cfreturn object />
</cffunction>

</cfcomponent>

Notice that once I instantiate the object (see Listing 4) I can then register each object into it:

Listing 6 - Application.cfm
...

<!--- register objects --->
<cfif NOT structKeyExists(application,"objectFactory") OR url.reInit>
<!--- registrant --->
<cfset application.objectFactory.register("Registrant","cfugdemo.com.model.registrant.Registrant") />
<cfset application.objectFactory.register("RegistrantGateway","cfugdemo.com.model.registrant.RegistrantGateway",true) />
<!--- fee --->
<cfset application.objectFactory.register("Fee","cfugdemo.com.model.fee.Fee") />
<cfset application.objectFactory.register("FeeGateway","cfugdemo.com.model.fee.FeeGateway",true) />
</cfif>

...

For those objects I want to be instantiated as singletons like RegistrantGateway and FeeGateway notice the third optional argument is set to true. Also, in this case we are registering all objects explicitly in code, you could also read an xml file with objects definition info in it and loop through the content and register them automatically. As you can see this ObjectFactory can now be reused in any of my applications without having to make application specific changes to it, it's also a bit faster in that it doesn't have to do any loop or switch statements to find the object to instantiate it (this would really be significant in applications with many objects but worth mentioning).

More Entries

BlogCFC was created by Raymond Camden. This blog is running version 5.003. Powered by ColdFusion Server v8,0,1,195765.