*polite request: can folks change the subject when the content wanders?*
On Friday, Nov 1, 2002, at 12:54 US/Pacific, S. Isaac Dealey wrote:
>> <cfset server.myVar = createObject("component","foo")/>
>> <cfset server.myVar.init()/>
> I'm curious. Can anyone explain to me why createObject() isn't enough
> to
> instantiate the object? I mean, why it is that <cfset
> server.myVar.init()/>
> would even be required here? It seems to me like the init() could just
> as
> well be an assumed part of a constructor for the object/cfc/etc... And
> better still because it would be less code and less prone to screw-ups
> that
> way.
Well, I think there's several very good reasons for using 'init()' for
your constructor:
1. It's how you deal with Java objects in CF (consistency; allows you
to switch implementations between Java and CFC easily)
2. The implicit constructor code execution is a little funky, e.g., I
don't think it has all the metadata set up correctly (since the
component instance is still 'under construction')
3. It's more flexible since you can pass in arguments
4. If CFMX adds named constructors a la Java/C++, you could just rename
init() to the named constructor (or write a named constructor that
called init() with the same arguments)
Sean A Corfield -- http://www.corfield.org/blog/
"If you're not annoying somebody, you're not really alive."
-- Margaret Atwood
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Archives: http://www.houseoffusion.com/cf_lists/index.cfm?forumid=4
Subscription:
http://www.houseoffusion.com/cf_lists/index.cfm?method=subscribe&forumid=4
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
Signup for the Fusion Authority news alert and keep up with the latest news in
ColdFusion and related topics. http://www.fusionauthority.com/signup.cfm