> -----Original Message-----
> From: [email protected]
> [mailto:[EMAIL PROTECTED] On Behalf Of Kevan Stannard
> Sent: Thursday, 13 November 2008 1:44 PM
> To: CFCDev
> Subject: [CFCDEV] Re: Is inheritance the right choice here?
>
>
> You could then use the method code as part of a file name
> convention, so you object creation could be like:
>
> <cfset contact = createObject("component",methodCode &
> "Contact").init ()>
>
> This idea removes the need to use switch/if statements in the code.
>
Kevin,
I'm not so keen on this sort of thing. Three reasons:
1. It assumes a 1-1 correspondence between the method and the implementing
class
2. The if block actually documents the allowed values. In your approach I
have to go and read the getMethodCode() function to work out what class my
factory method is actually going to instantiate - but which class to
instantiate is precisely my factory method's responsibility, not anyone
else's.
3. Error handling. I left the final case out for brevity, but the full thing
looks like:
if (query.contactType is "phone")
return CreateObject("PhoneContact").init(query.Field1,...)
else if (query.contactType is "email")
return CreateObject("EmailContact").init(query.Field1,...)
else
throw "unsupported contact type #query.contactType#"
As opposed to the more cryptic "file not found" error your approach would
produce. Furthermore, if there is some recovery to be done rather than just
throwing an exception, you'll have to check the methodCode against a list of
allowed values anyway.
Not wanting to start a war here - likely none of these objections apply to
what you're doing - but I just wanted to point out that there are some cases
where the string concatentation approach is to be avoided.
Jaime
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"CFCDev" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/cfcdev?hl=en
-~----------~----~----~----~------~----~------~--~---