Oops, i left where i instantiated the parent out of the code ... but in any case ...
Yes, it does help to have it spelled out in this way ... ;-) I didn't really *know* this when i started out: "A basic concept of inheritence is that Children may know about Parents ... but Parents do not know about Children" It just became clear that something wasn't working and i gave up on it. In any case, it still seems a little "conter-intuitive". Maybe that's why i've been confused about this. How can a parent not know about their children, especially if the children are inheriting from them?? Who's writing the will?? Geez, it's really important what metaphors we use to conceptualize things! I guess in the OO world, parents must have a fairly advanced case of alzheimer's. ;-) thanks Brendan! -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of Brendan O'Hara Sent: Monday, December 08, 2003 6:37 PM To: [EMAIL PROTECTED] Subject: RE: [CFCDev] Difficulty in getting the light bulb to turn on... Nando, You can combine lots of design patterns but you need to understand the basic principles of OOP otherwise you will get yourself lost pretty quickly. I do not see in your code where create a reference to OR "instantiate" the parent object or create a reference to OR "instantiate" the child object so how can you call methods on either? Also object properties should usually be defined or defaulted OUTSIDE a <CFFUNCTION> tag within the component tag body. A basic concept of inheritence is that Children may know about Parents (because of inheritene) but Parents do not know about Children. The Template Method Patterns describes referencing a Method in a Parent that is destined to be OVERRIDDEN by any useful Class inherting from it. That does not mean that the Parent Class knows anything about its "Children" because the Class that is always being instantiated in my example is the Child class which of course knows about itself. Does this help? Brendan "Nando" <[EMAIL PROTECTED]>@cfczone.org on 12/08/2003 11:30:12 AM Please respond to [EMAIL PROTECTED] Sent by: [EMAIL PROTECTED] To: <[EMAIL PROTECTED]> cc: Subject: RE: [CFCDev] Difficulty in getting the light bulb to turn on... 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] ---------------------------------------------------------- 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]
