Hello CF Superheroes,
I'm playing around with CFCs and I've run into a situation where I would like to start calling methods from some CFCs from within another CFC (nesting). My first instinct was to simply instance the CFCs from within the parent level CFC but I'm not sure ColdFusion would like it if I nest CFCs like that. I've read about some people getting the dreaded "null null" error at times.
I'm aware of the "extends" property from within the <cfcomponent> tag but the problem is that you wind up having to instance all of the extended CFCs in the calling CFM template anyway. It seems like it would just be easier to call the CFCs from within the CFCs that need to be "extended".
For example, here's what I'm thinking of doing:
In my main template index.cfm:
<cfobject component="MasterCFC" name="cfcs.master">
<cfset temp = masterCFC.myFunction()>
Then within master.cfc:
<cfcomponent>
<!--- get my sub cfc --->
<cfobject component="SubCFC" name="sub">
<cffunction...>
</cfcomponent>
Otherwise (as I understand it) if you wanted to use the "extends" property you would have to do it like this:
In my main template index.cfm:
<cfobject component="MasterCFC" name="cfcs.master">
<cfobject component="SubCFC" name="cfcs.sub">
<cfset temp = subCFC.functionFromMaster()>
Then within sub.cfc:
<cfcomponent extends="master">
<cffunction...>
</cfcomponent>
I'd love to hear your thoughts on how you nest CFCs or "extend" them efficiently.
Dave