RE: accessing parent cfc's variables
Good example Sean! If I misread the original poster, sorry. I thought for sure s/he was talking about inheritance. === Raymond Camden, ColdFusion Jedi Master for Mindseye, Inc Member of Team Macromedia (http://www.macromedia.com/go/teammacromedia) Email: [EMAIL PROTECTED] Blog : www.camdenfamily.com/morpheus/blog Yahoo IM : morpheus "My ally is the Force, and a powerful ally it is." - Yoda > -Original Message- > From: Sean A Corfield [mailto:[EMAIL PROTECTED] > Sent: Saturday, March 29, 2003 5:28 PM > To: CF-Talk > Subject: Re: accessing parent cfc's variables > > > On Saturday, Mar 29, 2003, at 07:52 US/Pacific, Raymond Camden wrote: > > It is true. If in parent.cfc, outside the methods or in a method but > > not > > var scoped or attribute scoped, if you do x=1, then child.cfc can > > access > > it as well. > > Let's try some real code here because I think some folks have gotten > confused: > ~| Archives: http://www.houseoffusion.com/cf_lists/index.cfm?forumid=4 Subscription: http://www.houseoffusion.com/cf_lists/index.cfm?method=subscribe&forumid=4 FAQ: http://www.thenetprofits.co.uk/coldfusion/faq Your ad could be here. Monies from ads go to support these lists and provide more resources for the community. http://www.fusionauthority.com/ads.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Re: accessing parent cfc's variables
On Saturday, Mar 29, 2003, at 07:52 US/Pacific, Raymond Camden wrote: > It is true. If in parent.cfc, outside the methods or in a method but > not > var scoped or attribute scoped, if you do x=1, then child.cfc can > access > it as well. Let's try some real code here because I think some folks have gotten confused: parent.cfc: child.cfc: pc.cfm: #p.parentMethod()# Now, *if* child (composition) objects can access their parent (enclosing) objects' non-public variables, this should dump an 'instance' struct containing 'x' and print "Parent X". Which it doesn't because a child (composition) object *cannot* see any of the enclosing object's data. Run it - it says "Variable INSTANCE is undefined." inside child.cfc. Hope that clarifies? If we were talking about inheritance then, yes, the derived object has access to all of the base object's data - because CFML has only a public scope ("this") and a protected scope (unnamed). Sean A Corfield -- http://www.corfield.org/blog/ "If you're not annoying somebody, you're not really alive." -- Margaret Atwood ~| Archives: http://www.houseoffusion.com/cf_lists/index.cfm?forumid=4 Subscription: http://www.houseoffusion.com/cf_lists/index.cfm?method=subscribe&forumid=4 FAQ: http://www.thenetprofits.co.uk/coldfusion/faq Get the mailserver that powers this list at http://www.coolfusion.com Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
accessing parent cfc's variables
Nevermind. It makes sense to me now. It is a parent-child relationship, of course. I agree with you, it wouldn't be good to access the parent's variables directly. I'm surprised you're able to at all. I'm new to objects- I was getting parent-child relationships confused with inheritance. >But this is not a parent-child relationship; it's composition! > >>It is true. If in parent.cfc, outside the methods or in a method but not >>var scoped or attribute scoped, if you do x=1, then child.cfc can access >>it as well. Does it make sense to use that feature? My gut instincts say >>no - even if I could access parent.cfc's private variables, I wouldn't >>count on it. >> >>=== >>Raymond Camden, ColdFusion Jedi Master for Mindseye, Inc >>Member of Team Macromedia (http://www.macromedia.com/go/teammacromedia) >> >>Email: [EMAIL PROTECTED] >>Blog : www.camdenfamily.com/morpheus/blog >>Yahoo IM : morpheus >> >>"My ally is the Force, and a powerful ally it is." - Yoda >> >>> -Original Message- >>> From: Brad Howerter [mailto:[EMAIL PROTECTED] >>> Sent: Saturday, March 29, 2003 8:38 AM >>> To: CF-Talk >>> Subject: accessing parent cfc's variables >>> >>> >>> Oh, yeah, I'd forgotten the original question. Raymond, you >>> said the 'lower' class has access to the unnamed scope of the >>> parent? I guess that's where I started thinking this was an >>> inherited object and not just one of composition. It's not >>> true, is it, that the unnamed scope would be available? If >>> the object is not inheriting its parent, why would have >>> access to the unnamed scope? >>> >>> >On Friday, Mar 28, 2003, at 08:02 US/Pacific, Brad Howerter wrote: >>> >> The child CFC automatically inherits all of its parents >>> values, so to >>> >> me it seems redundant to call a method to get them. >>> > >>> >That's true of inheritance not of composition. The question was about >>> >the latter. >>> > >>> >Sean A Corfield -- http://www.corfield.org/blog/ >>> > >>> >"If you're not annoying somebody, you're not really alive." >>> >-- Margaret Atwood >>> > >>> ~| Archives: http://www.houseoffusion.com/cf_lists/index.cfm?forumid=4 Subscription: http://www.houseoffusion.com/cf_lists/index.cfm?method=subscribe&forumid=4 FAQ: http://www.thenetprofits.co.uk/coldfusion/faq Structure your ColdFusion code with Fusebox. Get the official book at http://www.fusionauthority.com/bkinfo.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
accessing parent cfc's variables
But this is not a parent-child relationship; it's composition! >It is true. If in parent.cfc, outside the methods or in a method but not >var scoped or attribute scoped, if you do x=1, then child.cfc can access >it as well. Does it make sense to use that feature? My gut instincts say >no - even if I could access parent.cfc's private variables, I wouldn't >count on it. > >=== >Raymond Camden, ColdFusion Jedi Master for Mindseye, Inc >Member of Team Macromedia (http://www.macromedia.com/go/teammacromedia) > >Email: [EMAIL PROTECTED] >Blog : www.camdenfamily.com/morpheus/blog >Yahoo IM : morpheus > >"My ally is the Force, and a powerful ally it is." - Yoda > >> -Original Message- >> From: Brad Howerter [mailto:[EMAIL PROTECTED] >> Sent: Saturday, March 29, 2003 8:38 AM >> To: CF-Talk >> Subject: accessing parent cfc's variables >> >> >> Oh, yeah, I'd forgotten the original question. Raymond, you >> said the 'lower' class has access to the unnamed scope of the >> parent? I guess that's where I started thinking this was an >> inherited object and not just one of composition. It's not >> true, is it, that the unnamed scope would be available? If >> the object is not inheriting its parent, why would have >> access to the unnamed scope? >> >> >On Friday, Mar 28, 2003, at 08:02 US/Pacific, Brad Howerter wrote: >> >> The child CFC automatically inherits all of its parents >> values, so to >> >> me it seems redundant to call a method to get them. >> > >> >That's true of inheritance not of composition. The question was about >> >the latter. >> > >> >Sean A Corfield -- http://www.corfield.org/blog/ >> > >> >"If you're not annoying somebody, you're not really alive." >> >-- Margaret Atwood >> > >> ~| Archives: http://www.houseoffusion.com/cf_lists/index.cfm?forumid=4 Subscription: http://www.houseoffusion.com/cf_lists/index.cfm?method=subscribe&forumid=4 FAQ: http://www.thenetprofits.co.uk/coldfusion/faq Get the mailserver that powers this list at http://www.coolfusion.com Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
RE: accessing parent cfc's variables
It is true. If in parent.cfc, outside the methods or in a method but not var scoped or attribute scoped, if you do x=1, then child.cfc can access it as well. Does it make sense to use that feature? My gut instincts say no - even if I could access parent.cfc's private variables, I wouldn't count on it. === Raymond Camden, ColdFusion Jedi Master for Mindseye, Inc Member of Team Macromedia (http://www.macromedia.com/go/teammacromedia) Email: [EMAIL PROTECTED] Blog : www.camdenfamily.com/morpheus/blog Yahoo IM : morpheus "My ally is the Force, and a powerful ally it is." - Yoda > -Original Message- > From: Brad Howerter [mailto:[EMAIL PROTECTED] > Sent: Saturday, March 29, 2003 8:38 AM > To: CF-Talk > Subject: accessing parent cfc's variables > > > Oh, yeah, I'd forgotten the original question. Raymond, you > said the 'lower' class has access to the unnamed scope of the > parent? I guess that's where I started thinking this was an > inherited object and not just one of composition. It's not > true, is it, that the unnamed scope would be available? If > the object is not inheriting its parent, why would have > access to the unnamed scope? > > >On Friday, Mar 28, 2003, at 08:02 US/Pacific, Brad Howerter wrote: > >> The child CFC automatically inherits all of its parents > values, so to > >> me it seems redundant to call a method to get them. > > > >That's true of inheritance not of composition. The question was about > >the latter. > > > >Sean A Corfield -- http://www.corfield.org/blog/ > > > >"If you're not annoying somebody, you're not really alive." > >-- Margaret Atwood > > > ~| Archives: http://www.houseoffusion.com/cf_lists/index.cfm?forumid=4 Subscription: http://www.houseoffusion.com/cf_lists/index.cfm?method=subscribe&forumid=4 FAQ: http://www.thenetprofits.co.uk/coldfusion/faq Structure your ColdFusion code with Fusebox. Get the official book at http://www.fusionauthority.com/bkinfo.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
accessing parent cfc's variables
Oh, yeah, I'd forgotten the original question. Raymond, you said the 'lower' class has access to the unnamed scope of the parent? I guess that's where I started thinking this was an inherited object and not just one of composition. It's not true, is it, that the unnamed scope would be available? If the object is not inheriting its parent, why would have access to the unnamed scope? >On Friday, Mar 28, 2003, at 08:02 US/Pacific, Brad Howerter wrote: >> The child CFC automatically inherits all of its parents values, so to >> me it seems redundant to call a method to get them. > >That's true of inheritance not of composition. The question was about >the latter. > >Sean A Corfield -- http://www.corfield.org/blog/ > >"If you're not annoying somebody, you're not really alive." >-- Margaret Atwood > ~| Archives: http://www.houseoffusion.com/cf_lists/index.cfm?forumid=4 Subscription: http://www.houseoffusion.com/cf_lists/index.cfm?method=subscribe&forumid=4 FAQ: http://www.thenetprofits.co.uk/coldfusion/faq This list and all House of Fusion resources hosted by CFHosting.com. The place for dependable ColdFusion Hosting. Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Re: accessing parent cfc's variables
On Friday, Mar 28, 2003, at 08:02 US/Pacific, Brad Howerter wrote: > The child CFC automatically inherits all of its parents values, so to > me it seems redundant to call a method to get them. That's true of inheritance not of composition. The question was about the latter. Sean A Corfield -- http://www.corfield.org/blog/ "If you're not annoying somebody, you're not really alive." -- Margaret Atwood ~| Archives: http://www.houseoffusion.com/cf_lists/index.cfm?forumid=4 Subscription: http://www.houseoffusion.com/cf_lists/index.cfm?method=subscribe&forumid=4 FAQ: http://www.thenetprofits.co.uk/coldfusion/faq Signup for the Fusion Authority news alert and keep up with the latest news in ColdFusion and related topics. http://www.fusionauthority.com/signup.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Re: accessing parent cfc's variables
On Thursday, Mar 27, 2003, at 18:37 US/Pacific, [EMAIL PROTECTED] wrote: > If I have a cfc that is nested in another cfc, is there a way to > access the parent object's variables? > > I have something like this. > > > > > One option is to pass in the parent object reference (session.user) when you create the order and have the order remember it: if ( not structKeyExists(session.user,"order") ) { order = createObject("component", "cfc.order"); order.init( session.user ); session.user.order = order; } And inside order.cfc: ... rest of order.cfc ... ... instance.parent is owning user ... A couple of things to note here: - 'init()' matches what you do when manipulating Java objects (create, init) - 'init()' returns void - meaning "I return nothing" - 'instance' is convenient way to handle non-public instance data Sean A Corfield -- http://www.corfield.org/blog/ "If you're not annoying somebody, you're not really alive." -- Margaret Atwood ~| Archives: http://www.houseoffusion.com/cf_lists/index.cfm?forumid=4 Subscription: http://www.houseoffusion.com/cf_lists/index.cfm?method=subscribe&forumid=4 FAQ: http://www.thenetprofits.co.uk/coldfusion/faq Structure your ColdFusion code with Fusebox. Get the official book at http://www.fusionauthority.com/bkinfo.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
accessing parent cfc's variables
Should the encapsulation extend to the children, or should they know about their parent? I would think they'd know, since they have to know what methods to override and provide anyway. ~| Archives: http://www.houseoffusion.com/cf_lists/index.cfm?forumid=4 Subscription: http://www.houseoffusion.com/cf_lists/index.cfm?method=subscribe&forumid=4 FAQ: http://www.thenetprofits.co.uk/coldfusion/faq Your ad could be here. Monies from ads go to support these lists and provide more resources for the community. http://www.fusionauthority.com/ads.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
RE: accessing parent cfc's variables
It is a bit redundant, however, it adds a level of 'blackbox' to your architecture. So, for example, if the child needs to get a value from the parent, and you change the variable in the parent, all you would need to do is update the method, not the N children who extend the parent. === Raymond Camden, ColdFusion Jedi Master for Mindseye, Inc Member of Team Macromedia (http://www.macromedia.com/go/teammacromedia) Email: [EMAIL PROTECTED] Blog : www.camdenfamily.com/morpheus/blog Yahoo IM : morpheus "My ally is the Force, and a powerful ally it is." - Yoda > -Original Message- > From: Brad Howerter [mailto:[EMAIL PROTECTED] > Sent: Friday, March 28, 2003 10:03 AM > To: CF-Talk > Subject: accessing parent cfc's variables > > > The child CFC automatically inherits all of its parents > values, so to me it seems redundant to call a method to get > them. ~| Archives: http://www.houseoffusion.com/cf_lists/index.cfm?forumid=4 Subscription: http://www.houseoffusion.com/cf_lists/index.cfm?method=subscribe&forumid=4 FAQ: http://www.thenetprofits.co.uk/coldfusion/faq Structure your ColdFusion code with Fusebox. Get the official book at http://www.fusionauthority.com/bkinfo.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
accessing parent cfc's variables
The child CFC automatically inherits all of its parents values, so to me it seems redundant to call a method to get them. ~| Archives: http://www.houseoffusion.com/cf_lists/index.cfm?forumid=4 Subscription: http://www.houseoffusion.com/cf_lists/index.cfm?method=subscribe&forumid=4 FAQ: http://www.thenetprofits.co.uk/coldfusion/faq Signup for the Fusion Authority news alert and keep up with the latest news in ColdFusion and related topics. http://www.fusionauthority.com/signup.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
RE: accessing parent cfc's variables
If the value is in the this scope, or in the global, unnamed scope, the 'lower' CFC can access it. However, you probably want to use a method in the parent cfc, like getFoo(), to get the data. === Raymond Camden, ColdFusion Jedi Master for Mindseye, Inc Member of Team Macromedia (http://www.macromedia.com/go/teammacromedia) Email: [EMAIL PROTECTED] Blog : www.camdenfamily.com/morpheus/blog Yahoo IM : morpheus "My ally is the Force, and a powerful ally it is." - Yoda > -Original Message- > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] > Sent: Thursday, March 27, 2003 8:37 PM > To: CF-Talk > Subject: accessing parent cfc's variables > > > If I have a cfc that is nested in another cfc, is there a way > to access the parent object's variables? > > I have something like this. > > > > > > > I have a method in the order object that needs to access a > variable in the this scope of the user object. > > ~| Archives: http://www.houseoffusion.com/cf_lists/index.cfm?forumid=4 Subscription: http://www.houseoffusion.com/cf_lists/index.cfm?method=subscribe&forumid=4 FAQ: http://www.thenetprofits.co.uk/coldfusion/faq Signup for the Fusion Authority news alert and keep up with the latest news in ColdFusion and related topics. http://www.fusionauthority.com/signup.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
accessing parent cfc's variables
If I have a cfc that is nested in another cfc, is there a way to access the parent object's variables? I have something like this. I have a method in the order object that needs to access a variable in the this scope of the user object. -- mailto:[EMAIL PROTECTED] ~| Archives: http://www.houseoffusion.com/cf_lists/index.cfm?forumid=4 Subscription: http://www.houseoffusion.com/cf_lists/index.cfm?method=subscribe&forumid=4 FAQ: http://www.thenetprofits.co.uk/coldfusion/faq This list and all House of Fusion resources hosted by CFHosting.com. The place for dependable ColdFusion Hosting. Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4