On Mar 16, 2004, at 1:58 AM, Jeffry Houser wrote:
5. Always have an init() method that acts as your constructor and returns "this" (unless you are building a web services/flash remoting
 facade.)


 I understand that using this approach you can call the init() method and create your instance w/ one cfinvoke tag.  Why is this better than using the "psuedo-constructor" which will operationally do the same thing.  ( Or even the BD cfconstructor tag )

The pseudo-constructor cannot take arguments - init() can.


BD's <cfconstructor> tag is a good idea but isn't portable - BD allows for init() to call the <cfconstructor> if it is defined (thus preserving "use" compatibility for init() methods) but will call init() if no <cfconstructor> is present (just like CFMX).

As you observe, defining init() and having it return "this" means that in addition to this:

<cfset obj = createObject("component","foo").init(arg) />

you can also do this with the same effect:

<cfinvoke component="foo" method="init" returnvariable="obj" />

Defining init() to return "this" allows you to write code that matches the Java behavior in CFMX:

<cfset jObj = createObject("java","com.acme.foo").init(arg) />

6. Always (with rare exceptions) use OUTPUT="false" in your CFFUNCTION and CFCOMPONENT tags. Do not output directly to the buffer inside a CFC method -- instead return a string.

 Why?  Are there known performance issues? 

This is mostly a separation of presentation and logic issue. Some people think it's fine to have a CFC whose sole purpose is to output HTML (I'm ambivalent about that), others think no CFC should ever output HTML. Most people seem to agree that you shouldn't really mix output methods in with logic methods...


As with in regular CFML pages, I consider a best practice to be to scope all your variables.  With that said, would your optional / well worn best practice better be stated as "variables.instance.xx"? 

I agree. I only use the "instance" struct idiom for an object's state that I intend to persist (using the memento / DAO idiom) and I always write it as "variables.instance".


Sean A Corfield -- http://www.corfield.org/blog/

Got Mach II? -- http://www.mach-ii.com/

----------------------------------------------------------
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