Jon, indeed you are correct with that example. I see i've been trying to do something
slightly different, following, or maybe misfollowing, the Template Method pattern
article in CFDJ - and that created part of the impression.

<cfcomponent name="Parent" >

<cffunction name="init" access="public" returntype="any">
        <cfset Variables.Name = "I'm an object in a family" >
        <cfset variables.theChild = createObject('component','Child')>
        <cfreturn this />
</cffunction>

<cffunction name="getChild" access="public" returntype="any">
        <cfreturn variables.theChild>
</cffunction>
</cfcomponent>

<cfcomponent name="Child" extends="Parent">
  <cffunction name="GetName" >
    <cfreturn Variables.Name >
  </cffunction>
</cfcomponent>

<cfset family = theParent.getChild().GetName() />

This gives me an "Element NAME is undefined in VARIABLES" error on the GetName method.
So I see you can't "combine" inheritance and composition now in this way. The child
element needs to be instantiated outside of the parent element, probably in the same
variable space. I wasn't so clear about that until now.

Thanks! That cleared something else up for me!

:^)  <sporting-bright-nosed-grin>

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
Behalf Of Jon Gunnip
Sent: Monday, December 08, 2003 4:08 PM
To: [EMAIL PROTECTED]
Subject: RE: [CFCDev] Difficulty in getting the light bulb to turn on...




>>> [EMAIL PROTECTED] 12/08/03 03:04AM >>>
> Another is that i'm beginning to see that inheritance is "nearly useless" in CF -
> well, that's a broad statement, but for the most part it's kinda true, because all
> that is inherited is the methods. The instance data isn't inherited, because it's
only
> class inheritance, not object inheritance. So if you need the instance data in the
> subtypes, and you probably will, you still need to pass it down to the subtype using
> ... you got it, composition.

Component data (vars in the "Variables" scope) is inherited by "child" components.  I
am using it to good effect in a Unit Testing system that I work with.

Inheritance isn't always "evil" or useless - you should just make sure it is the best
solution for your problem rather than jumping into it without much thought.  There are
some situations where it provides a very elegant solution over other options.

<cfcomponent name="Parent" >
  <cfset Variables.Name = "I'm an object in a family" >
</cfcomponent>

<cfcomponent name="Child" extends="Parent" >
  <cffunction name="GetName" >
    <cfreturn Variables.Name >  // returns "I'm an object in a family"
  </cffunction>
</cfcomponent>

Jon




----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email
to [EMAIL PROTECTED] with the words 'unsubscribe cfcdev'
in the message of the email.

CFCDev is run by CFCZone (www.cfczone.org) and supported
by Mindtool, Corporation (www.mindtool.com).

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


----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email
to [EMAIL PROTECTED] with the words 'unsubscribe cfcdev' 
in the message of the email.

CFCDev is run by CFCZone (www.cfczone.org) and supported
by Mindtool, Corporation (www.mindtool.com).

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

Reply via email to