What you are doing is a very widely accepted methodology.  However, people differ on whether the "isInitialized" is necessary -- I think it depends on the audience for your components.  If you are building them for an internal team, I tend to think it's not necessary to check for initialization and let errors thrown during development catch any non-initialized components (it should be immediately apparent to a developer there's something wrong -- and you can use try/catch blocks if you want more specific error messages).  If you are building software development kits for use by a wider audience then the case for doing the extra checking (and presumably throwing well articulated exceptions) seems better, in my opinion.
 
BTW, you don't need to do a CFIF inside your methods -- why not just call something like:
 
initCheck();
 
Then inside initCheck you can do your conditional logic/exception raising -- makes your individual methods a little cleaner, IMO.
 
One variation on your code I've seen is rather than passing a specific Application variable in, you create a CFC that manages your "global" variables -- you can then cache that component in the Application scope and pass a reference to it into your init() methods.  Then you can use the API of your global variables manager inside your components.  This is a slightly more elegant solution, again, IMO.  It also saves you from later deciding you need to change which of your global variables need to be available inside a given component, and thus potentially saves you API change headaches down the road.  You could do something similar with a CFC that acts as a session facade.
 
 
 
 
 
 
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]On Behalf Of Barry Beattie
Sent: Sunday, May 23, 2004 4:17 PM
To: [EMAIL PROTECTED]
Subject: [CFCDev] constructors and initialisation

hi all

 

is there no way of passing parameters into a CFC on invocation?

 

At present I’ve got an init() method that takes in application DSN and session security info and returns THIS.

 

eg:

<cfset objReqAdmin = createobject("component", "#APPLICATION.componentPath#.reqadmin").init(APPLICATION .dsnInfo, SESSION.userinfo)>

 

Without these, the component methods should not function so I’ve got a kludgy <cfif isInitialised> at the top of every method to stop use without initialising first. not the neatest solution.

 

Without resorting the CFCs accessing session and application scopes directly (bad news in my book), is there no other way?

 

thanx

barry beattie

 

 

Reply via email to