> -----Original Message-----
> From: Jeff Small [mailto:[EMAIL PROTECTED]
> Sent: Tuesday, December 28, 2004 11:39 AM
> To: CF-Talk
> Subject: My Init() in my CFC...am I on the right track?
> 
> <cfset init()>
> 
> <cffunction name="init" access="private" output="false"
> returntype="string"
> displayname="Initializes my object and creates the datasource variable">
>     <cfset variables.DSN = "myDataSourceName">
>     <cfreturn variables.DSN>
> </cffunction>

This should work, but I would definitely accept the name of the datasource
as an argument if it might change.  I don't know what the purpose of this
CFC is, but I can't see any reason that you would want the CFC to be
modified in that case - it should be modified at the point the CFC is
instantiated (I think).

The only other point is that it's common (and I think very good) practice to
return "this" from the init() method.

This returns the instance of your CFC to the caller, which is most often
what you want to do in the case of initialization.  Something like this:
]
<cfset Application.MyDSNCFC = CreateObject(ThatCFC_Up_There).init() />

The CreateObject() function returns the CFC instance, so you can chain the
init() call it to it.  Since the init() call also returns "this" (the CFC
instance) you can assign it directly to a variable container as is.

I hope I'm making sense, I've just woken up...

Jim Davis




~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Special thanks to the CF Community Suite Silver Sponsor - RUWebby
http://www.ruwebby.com

Message: http://www.houseoffusion.com/lists.cfm/link=i:4:188869
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54

Reply via email to