From: Rich Kilmer Date: 2002-02-14T04:51:49+09:00 Subject: RE: qualms about respond_to? idiom > -----Original Message----- > From: Paul Brannan [mailto:paul@atdesk.com] > Sent: Wednesday, February 13, 2002 11:27 AM > To: ruby-talk ML > Subject: Re: qualms about respond_to? idiom > > > On Thu, Feb 14, 2002 at 01:11:39AM +0900, Dave Thomas wrote: > > start tags would have > > > > def handle_stack(stack) > > stack.push(name) > > end > > Does this really belong in the stream object itself? Should a tag have > to have knowledge of how the data structure it is being put into > operates? What if I wanted to create a binary tree of tags and other > stream elements; should I then have a handle_binary_tree method in all > my stream objects? > > Using your solution seems nice, since it means that the dispatcher needs > less knowledge about the objects it is handling, but it means that the > objects need more knowledge about the dispatcher. Is there a good way > around this tradeoff? > > Paul > In Dave's example he shifted the responsibility of the tag object to handle stacking. Realize that we are not speaking of a general type of object, but a specific one (an xml tag). One thing you know about xml tags is they (by defintion) are hierarchical (thus lend themselves to stacking). At the same time, you may not always need to stack (if you are scanning, etc), so making it an optional behavior where you pass in your stack object makes sense. -rich