Another way of explaining it is that it avoids you having to do this:

<cfset x = CreateObject("component","foo") />
<cfset x.init() />


Instead you can 'method chain' in one shot:


<cfset x = CreateObject("component","foo").init() />

The init is returning a 'handle' or reference to the component itself.

But this is just a developer *convenience*, not really a *best practice*. To me, a best practice should be along the lines of proper variable scoping, the use of the "output" attribute, etc. Telling me how to return my init() method is not a best practice, it's you dictating how to *design* my CFCs, which shouldn't be the point of a best practices document.


Also, as Matt pointed out in his point, I personally feel that returning "this" is merely a workaround for the fact that there are no constructors in Macromedia ColdFusion (guess we need to start distinguishing between MM's and NA's versions!!). Further, I think it's confusing to novices who, on the one hand read that you shouldn't use the "this" scope in CFCs because the variables are then accessible to calling code, but then, on the other hand, read that it's OK to return "this" from your init() method. It's contradictory to those who may not have OO experience (and maybe even some of those who do!).

Outside of habit from other languages, is it really that hard to break up the createObject() statement and the init() call? I think it's clearer to all levels of developers, and magnifies the fact that what we really need is a constructor mechanism.

Just my opinion.

Regards,
Dave.

_________________________________________________________________
Create a Job Alert on MSN Careers and enter for a chance to win $1000! http://msn.careerbuilder.com/promo/kaday.htm?siteid=CBMSN_1K&sc_extcmp=JS_JASweep_MSNHotm2


----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email
to [EMAIL PROTECTED] with the words 'unsubscribe cfcdev' in the message of the email.


CFCDev is run by CFCZone (www.cfczone.org) and supported
by Mindtool, Corporation (www.mindtool.com).

An archive of the CFCDev list is available at www.mail-archive.com/[EMAIL PROTECTED]

Reply via email to