On Sun, Sep 27, 2009 at 6:22 PM, Kevin Pepperman <chorno...@gmail.com> wrote:
> Using an init() method, although not required, is considered best practice
> in the CF world for initializing components because cfc's don't have true
> constructors like JAVA (yet).

Just a couple of points to elaborate on this...

We use init() on CFCs because it mimics how we have to interact with
Java classes:

<cfset jObj = createObject("java","java.lang.String").init( "Hello" ) />

Calling the "constructor" method init() in a CFC means it looks the same in use:

<cfset cfObj = createObject("component","path.to.MyObject").init( "Hello" ) />

Also, in CF9 - and in the CFML2009 spec - the new operator calls
init() automatically:

import path.to.MyObject;

cfObj = new MyObject( "Hello" );

Based on that syntax - and its behavior - I'd say we *do* have
constructors, they just happen to be called init().

Remember: a constructor is simply a method that is called to do
initialization (and different languages call their constructors
different names).
-- 
Sean A Corfield -- (904) 302-SEAN
Railo Technologies US -- http://getrailo.com/
An Architect's View -- http://corfield.org/

"If you're not annoying somebody, you're not really alive."
-- Margaret Atwood

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Want to reach the ColdFusion community with something they want? Let them know 
on the House of Fusion mailing lists
Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:326683
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4

Reply via email to