Frameworks Conference: Intro to Object Factories - Rob Gonda

Talked about how developers moved to using CFCs and ended up with "The Big Object." (Take a look at BlogCFC.) Other problems you can get into with CFCs include:

Who creates the object? Who inits it? What is required to init a CFC? In other words, if component A makes an instance of component B and the requirements for creating B changes, you now have multiple places to update it.
What about the relationships between objects?
What if you move stuff?
Unit testing - how do you unit test A if it depends on B?

Here is where design patterns can help us out. The pattern covered is the Object Factory.

It handles created objects. One place to create objects. All objects need the factory (so its passed to all objects)

Inversion of Control (IoC) takes it farther. Dependency Injection - this is a form of IoC. Again - it is about moving the responsibility of creating objects from N components to 1 component. 3 types of DI: setter, constructor, and interface-based injection.

ColdSpring - this is an IoC framework. Allows for CFC dependency injection. Borrows XML syntax from Spring (but is not a real port).

Rob used Galleon as a good example of how the factory can help approve code, and I couldn't agree more.

Very, very darn good presentation by Rob. I'm going to try to build an object factory for my readers next week to show a good example.

Comments

I did an example of a service factory yesterday...

http://www.markdrew.co.uk/blog/index.cfm/2007/2/1/...
# Posted By Mark Drew | 2/2/07 7:31 AM
Nice. Although I'm still going to post an example too. ;) (I only learn something if I write it myself.)
# Posted By Raymond Camden | 2/2/07 7:36 AM
The first half of Rob's preso was essentially my Managing ColdFusion Components with Factories talk that I gave at a number of CFUGs last year and at cf.Objective() and CFUNITED. The second half of his preso was essentialy what Dave Ross and Chris Scott were touting last year (the IOC and AOP stuff). Glad that it gave you food for thought tho'...
# Posted By Sean Corfield | 2/4/07 2:46 AM
Very funny Sean; I would have loved to hear your comments had you assisted my preso, but I don't remember seeing you there. I had one of your slides and one from Dave, but you could see for yourself once I post the final slides and code. Make sure to download the podcast so you can get a better feeling of what you missed.

Cheers.
# Posted By Rob Gonda | 2/5/07 12:11 PM
Rob, I was referring to the slide printouts in the Frameworks Conference booklet. I'm not saying that basing your material on mine and Dave's / Chris's was in any way wrong, merely that it wasn't new material - it was stuff that was presented at last year's CFUNITED. I'm always happy for people to use my material to create their own presos.

And anyone looking at your slide printout in the booklet and my old factories talk will see a lot more than one slide's worth of common material...
# Posted By Sean Corfield | 2/5/07 4:22 PM
The community certainly appreciates your open and selfless contributions. You're right; the printouts were part of an initial draft which was later modified, adding code examples, reverse engineering of open source applications, step by step architecture process and thought flow to better explain the reasons for those who never experienced the problems factories solve.
# Posted By Rob Gonda | 2/5/07 7:00 PM
# Posted By Rob Gonda | 2/21/07 8:15 AM