Oh and it also makes you child more flexible since they aren't listening for specific events. The parent could change it's interface: say change a text field to a combo box, and the child doesn't care. Another benefit of decoupling.
Charlie On Thu, May 14, 2009 at 10:17 PM, Charlie Hubbard <[email protected] > wrote: > I'm not entirely sure I understand what you're asking, but here goes. > > I'm assuming you have a parent component and a child component of which the > parent is instantiating the child. So A is parent, B is child. A contains > B. So the parent is aware of the child, but not necessarily the other way > around. This is an important rule to follow if you want to keep your > software easy to change. Keeping the child unaware of the parent it is > contained within makes it easier to reuse in other contexts which makes your > software easier to change. That's called decoupling. B doesn't depend on > A. > > My suggestion is have the parent route whatever message the child needs to > it. Don't worry about registering listeners in this case. Have the parent > listen for it's events, then have that event listener make a call to the > child to signify the state has changed. That keeps them decoupled, and it's > straight forward. > > Charlie > > On Thu, May 14, 2009 at 7:38 PM, Laurence MacNeill > <[email protected]>wrote: > >> How do I get a Child to listen for events that occur in the Parent? >> >> I know how to get the Parent to listen for events in the Child -- that's >> relatively easy. But I don't know how to make the reverse happen. I would >> think there'd be a way to do that, but I just can't figure it out. >> >> Thanks for any help you can offer, >> >> >> Laurence MacNeill >> Mableton, Georgia, USA >> >> >> >> ------------------------------------------------------------- >> To unsubscribe from this list, simply email the list with unsubscribe in >> the subject line >> >> For more info, see http://www.affug.com >> Archive @ http://www.mail-archive.com/discussion%40affug.com/ >> List hosted by http://www.fusionlink.com >> ------------------------------------------------------------- >> >> >> >
