On 11/3/05, Barney Boisvert <[EMAIL PROTECTED]> wrote:
> I happen to like that style (though I use getInstance), even though it
> goes against one of the common tenets of OO: "never pass in
> behaviour-dicating method arguments, make separate methods instead."
> Like Scratch/Baz suggested, getInstance will delegate to
> class-specific factory methods where appropriate, but some classes of
> object (gateways come to mind) are frequently initialized in the same
> way (pass in the DSN to use).
You've created a situation where introducing an object that's not
initialized the same way is painful. So instead of doing the right
thing, you may be tempted to force your object to intialize the same
as all the others. Otherwise, you have to introduce a -- *gulp* --
special case.
Also, aren't you a fan of strong typing? What do you make the
returntype of a method that returns lots of different types?
> With a single getInstance, I can have a 'default' initialization
> routine, and specialize it where needed, saving some code. It's also
> a structure that'll work no matter whether you can make that code
> reduction or not, and consistency, consistency, consistency.
You can make the same code reduction by having a single method per object.
<cffunction name="createSecurityService">
<cfreturn createObject("component", "security").init()/>
</cffunction>
<cffunction name="createFooGateway">
<cfreturn createGateway("foo", variables.dsn)/>
</cffunction>
<cffunction name="createBarGateway">
<cfreturn createGateway("bar", variables.dsn)/>
</cffunction>
Only this way you don't need a switch statement.
<tangent>
What's going on here? We drag someone through the mud for
advocating get(fieldname) and set(fieldname, value). Then Hal
does the same thing with his isNull(fieldName) method. Now
you and Nando are getting into the game.
If you're worried about having lots of public functions in your CFC,
may I suggested the universally useful do() template?
<cffunction name="do" access="public" returnType="any" hint="It depends...">
<cfargument name="action" type="string"/>
<cfargument name="parameters" type="struct" optional="true"/>
<cfswitch express="#arguments.action#">
<!--- insert code here --->
</cfswitch>
</cffunction>
</tangent>
Patrick
--
Patrick McElhaney
704.560.9117
http://pmcelhaney.weblogs.us
----------------------------------------------------------
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]