Mike,
I
enjoyed reading your posts this morning, especially the one about the throngs of
bank customers meeting in the road.
It's
hard for me too. Someone will say, for instance, that a Service is X. Then
someone else will say that a Service is Y and that X is a Manager. Then someone
else will say that if you are using Managers in your model, you don't understand
OO design very well. Then Joe gets around that in Model-Glue by calling them
Controllers, and i think to myself, "Gee, that was clever!"
;)
I'm going to call it a Service. Think of the guy in the
truck selling hot dogs to the throngs of bank customers crossing the road.
That's a Service, right?
Here's what i've done, in case it's of any
help.
In Application.cfc/m instantiate Factory as a
singleton. Then have Factory make you instance of DaoService. When it does, pass
the instance of the factory into it, using "this".
in Factory:
<cffunction name="getDaoService" access="public"
returntype="DaoService" output="no">
<cfset var DaoService = createObject('component','DaoService').init(this) />
<cfreturn DaoService />
</cffunction>
<cfset var DaoService = createObject('component','DaoService').init(this) />
<cfreturn DaoService />
</cffunction>
In Application.cfc/m, or
wherever actually needed.
(adjust as necessary)
<cfif NOT
StructKeyExists(application, "DaoService") OR StructKeyExists(url,
"reinit")>
<cfset application.DaoService = application.Factory.getDaoService() />
</cfif>
<cfset application.DaoService = application.Factory.getDaoService() />
</cfif>
In DaoService's init method, you'll set the Factory
instance you passed into DaoService to variables scope so you've got ready
access to it, and then from within DaoService, have factory make all the Dao's
you need and set them to variables scope as
well.
Then you'd access them using public getters. For
example:
application.DaoService.getSomeSpecificDao().create()
application.DaoService.getSomeSpecificDao().read()
I've used this approach to instantiate Gateways into a
GatewayService for front end queries. It seems to perform very well, even on
views that use many queries to render the
page.
I'm not suggesting that you specifically use an object
called DaoService - btw. It's just to
demonstrate.
ciao,
Nando
---------------------------------------------------------------Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]On Behalf Of Mike Kear
Sent: Monday, November 14, 2005 8:04 AM
To: [email protected]
Subject: Re: [CFCDev] Factory Pattern - yes this IS about Factory Pattern!Thanks for the link to the Joe article, Sean. It is excellent. It definitely meets the needs I was looking for - not too technical.It seems this whole subject is difficult for a lot of people to discuss in terms that us neophytes can easily grasp. For a long while, every time i THOUGHT I had a handle on it, someone would use some other term I didnt understand, and i'd take time to figure out whether this was a new term for a concept i already knew about, or a new concept I didnt know about yet.Joe, congrats on a well-written, easy to understand couple of articles on the factory and the DAO concepts, and how they relate to CF users. Nicely done, and thanks a lot!Cheers
Mike Kear
Windsor, NSW, Australia
Certified Advanced ColdFusion Developer
AFP Webworks
http://afpwebworks.com
ColdFusion, PHP, ASP, ASP.NET hosting from AUD$15/monthOn 11/14/05, Sean Corfield <[EMAIL PROTECTED]> wrote:----------------------------------------------------------On 11/13/05, Mike Kear <[EMAIL PROTECTED]> wrote:
> Right, Sean, and I should have changed it in my last post too. Sorry
> everyone.
And I responded without changing the subject too - mea culpa! (Can I
claim you're a bad influence on me, Mike? No? I didn't think so!)
> But since this subject line is about factory patterns, does anyone know a
> not-too-technical place where I can go to learn about it, preferably on
> line?
"not-too-technical" That's a tough question.
I just searched for "factory pattern" on Google and got over 90,000 results :(
I think this post by Joe Rinehart is very good - and reasonably approachable:
http://clearsoftware.net/client/index.cfm?mode=entry&entry=89F69AD3-E081-2BAC-695BECE0066A7203
--
Sean A Corfield -- http://corfield.org/
Got frameworks?
You are subscribed to cfcdev. To unsubscribe, send an email to [email protected] with the words 'unsubscribe cfcdev' as the subject of the email.
CFCDev is run by CFCZone (www.cfczone.org) and supported by CFXHosting (www.cfxhosting.com).
An archive of the CFCDev list is available at www.mail-archive.com/[email protected]
You are subscribed to cfcdev. To unsubscribe, send an email to [email protected] with the words 'unsubscribe cfcdev' as the subject of the email.
CFCDev is run by CFCZone (www.cfczone.org) and supported by CFXHosting (www.cfxhosting.com).
An archive of the CFCDev list is available at www.mail-archive.com/[email protected]
