Hahaha – I had a feeling you’d reply Nando

 

Well the main purpose of implementing the factory was to simplify: createObject(WhichArgAgain?, WhatOrder?)

 

So if I had a User.cfc that always needed 5 EMPTY objects, the factory works like a charm… I would just create the 5 ojects in my createUser() factory method and pass them into the User.cfc. For this to work, my User.cfc’s init() would have to accept the 5 objects as arguments – which means that I need to call that init() in my Factory…

 

So I’m not a big fan of the first suggestion of init’ing after the create because I would be calling init() twice…

myInstance = application.Factory.load('myObj')

myInstance.init(InitParametersCouldGoHere)

 

The second suggestion of passing optional arguments seems closer to the mark… but now I’m complicating the intended simplicity of the Factory – if I have 300-400 create methods, I’ll never remember which ones require external arguments and which don’t – so I’ll have to keep referring back to the Factory file, finding the specific create() and verifying the required arguments…

 

Barney mentioned this in his last post:

“Anything needing to be passed to init must be available to the factory, and should NOT be dynamic. Every object is created in exactly the same way.  Once you have the instance, then you can supply custom state, if appropriate.”

 

Enforcing that rule solves the problem of not knowing which arguments to pass at create time but introduces the new problem of having to remember to call certain sets right after creating – a strange dependency.  This could cause even more problems because how am I even supposed to know which sets are mandatory right after create and which are just regular sets that can be performed anytime.

 

I was thinking of actually having an init2() method in addition to init() for the CFC’s that require statefull objects as parameters… That way I maintain the simplicity of creation a la Barney, avoid calling init() twice, and can know a little more easily that additional params are required…

 

It just seems like that’s the type thing that’s gonna get you fired…

 

Baz

 

 

 


From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Nando
Sent: Wednesday, November 02, 2005 1:07 AM
To: [email protected]
Subject: RE: [CFCDev] Factory Pattern

 

:) - back so soon?

 

myInstance = application.Factory.load('myObj')

myInstance.init(InitParametersCouldGoHere)

 

 or what about this?

 

myInstance = application.Factory.load('myObj',args)

 

<!--- load --->

<cffunction name="load" access="public" returntype="any">

            <cfargument name="ObjectName" type="string" required="yes" />

           <cfargument name="args" type="struct" required="no" />

 

 

Which do you like better? If you prefer one over the other, why?

 

 

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]On Behalf Of Scratch
Sent: Wednesday, November 02, 2005 6:15 AM
To: [email protected]
Subject: [CFCDev] Factory Pattern

 

I was recommended to build a Factory object to create my CFCs in the following manner:

 

<!--- init --->

<cffunction name="init" access="public" returntype="SystemFactory">

            <cfreturn this />

</cffunction>

 

<!--- load --->

<cffunction name="load" access="public" returntype="any">

            <cfargument name="ObjectName" type="string" required="yes" />

 

            <cfset var ObjectInstance="" />

 

            <cfinvoke method="create#arguments.ObjectName#" returnVariable="ObjectInstance" />

                       

            <cfreturn ObjectInstance />

</cffunction>

 

<!--- createObjectXXX --->

<cffunction name="createObjectXXX" access="private" returntype=" ObjectXXX ">

                       

            <cfset var Object=createobject('Component','SystemCFC.ObjectXXX).init() />

                                               

            <cfreturn Object />

</cffunction>

 

The load() method takes a CFC name and calls the appropriate Create() method. My app should only call load().

 

First off is this a good way? Secondly, if I use this way I seem to lose the ability to pass already instantiated objects to my init() methods - ofcourse I can still create new dependent objects and pass them in, which is the point of the whole thing, but what about passing in already instantiated objects? How does that work with Factories?

 

Anyone care to post a link to their Factory file ;-)

 

Cheers,

 

Baz

----------------------------------------------------------
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]

----------------------------------------------------------
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]

Reply via email to