As far as i understand, the init() method's job is to get an object in a state where it's ready to use. If other methods in the object require access to a variable, like a DSN for instance, or an object, the init() should provide for that.

In Java, the init() function is called automatically when an instance is of an object is created. In CF, it is not - it's just a convention. It's up to the developer to remember to call it. The purpose of the convention is to give us a common method to use to initialize an object, so we understand our own and each other's code more easily. The purpose of chaining the init() call by convention is to group object instantiation with it's initialization, like Java does automatically.

Today, your utility cfc doesn't need initialization. If you're not using a factory, you might have many places in your code with createObject calls like

<cfset var SortMaster = CreateObject("Component",
"CAMSymphony.model.util.SortMaster") />
"Tomorrow", you might decide to change SortMaster in a way that requires initialization. Assuming your app is live, you might have a delicate dance deploying the change without breaking your app. And you'll need to touch much more code than you would if you already had the init() in place.

Now in this particular case, it might not be a big deal. But the larger the app, the more these considerations come into play.


Joshua Scott wrote:
All,

I have a two function utility cfc that I use to create sortable columns for
record displays. Always before I have called

<cfset var SortMaster = CreateObject("Component",
"CAMSymphony.model.util.SortMaster") />

Many of the framework and OO oriented CFC patterns that I have seen actually
have a init() method and are created like this:

<cfset var SortMaster = CreateObject("Component",
"CAMSymphony.model.util.SortMaster").init() />

I understand the purpose in the frameworks for using this pattern, but in a
simple cfc is there a purpose for this? 

Any advise would be great.

- JS

 

------------------------------------------------
Joshua Scott
Resonant Media Technologies, LLC.
http://www.resonantmedia.com | http://ponderings.wordpress.com 
 

"It is impossible to get out of a problem by using the same type of thinking
that it took to get into the problem." -- Albert Einstein
 

 



----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email to [email protected] with the words 'unsubscribe cfcdev' as the subject of the email.

CFCDev is run by CFCZone (www.cfczone.org) and supported by CFXHosting (www.cfxhosting.com).

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



  


--


Aria Media Sagl
CP 234
6934 Bioggio
Switzerland
www.aria-media.com


Reply via email to