On Sat, Feb 7, 2009 at 10:12 PM, Mike Soultanian <[email protected]> wrote:
> > Yeah, I noticed that the book uses the "this" scope. I also noticed > that the book outputs data from CFCs which I've read is a nono in > regards to best practices. I'm assuming the correct method to retrieve > the data stored in the properties is by calling the class' methods, > correct? > Right, when the book was written there was no "private" variables scope available within a CFC, except via a hack (which the book will show and which you can ignore). Correct me if I'm wrong, but based on my initial reading of CFCs on the > web, it seems like there are three ways of setting up constructor data: > putting any cf tags or functions in the constructor area, putting a > <cfset init()> statement in the constructor area that calls the init() > method, or calling the init() method during the object instantiation. > Is there a preferred method? Yes, as Brad mentioned, it is the common practice to chain an init() call when you create the object. It does mean that your init() method needs to return "this": <cffunction name="init"> <cfreturn this /> </cffunction> > Maybe I'm not understanding the goal of the init() method and to whom > that data is supposed to be made available. Is it for the purpose of > providing data to the newly created object or is it to initialize data > for the other methods in the class.. or both? If anyone has any pages > describing constructors and their uses (even if it's in another > language), that would be helpful. > http://en.wikipedia.org/wiki/Constructor_(computer_science) A constructor in most languages is a block of code that is automatically executed when the object is created. So it is a place to set up the object and put it into a usable state. Since we don't have constructors in ColdFusion, the init() method has to be explicitly called. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to date Get the Free Trial http://ad.doubleclick.net/clk;207172674;29440083;f Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:319033 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4

