"Hugh Sasse Staff Elec Eng" <hgs / dmu.ac.uk> schrieb im Newsbeitrag 
news:Pine.GSO.4.60.0501271730040.4366 / brains.eng.cse.dmu.ac.uk...
> On Fri, 28 Jan 2005, Trans wrote:
>
>>> I have run into this problem myself, and have not seen a good
>>> solutoin to it. I have a suspicion that it probably means the
>>> separation of the two classes, in this case Parser and Token,
>>> is an incorrect model, because they both need access to each
>>> other.
>>
>> Hmm...  I'm not sure how that can be outside of through OOP out the
>> window. If I combine the Token and the Parser into a single thing then
>> that will really be the only thing there is ;-)
>
> Yes.  That's why I only consider it a suspicion, and why I say I
> haven't seen a good answer to it yet.

Not much time, so just a short anwer in between: I think the proper model is 
a parsing context.  Part of that context could be a stack of parsers or a 
current parser that knows its ancestor.  I would definitely not use classes 
here but instances.

> Thinking out loud:  What if when instance vars were created they got
> a container() method which returned the containing class?  Or maybe
> have a contains keyword like attr (and friends) that sets this up
> for you.  It feels like unwanted coupling, though.

Yeah, but that's the solution.  The context can have factory methods for 
this.

module ContextAware
  attr_accessor :context
end

class Context
def create(cl,*a, &b)
  x = cl.new(*a, &b)
  x.context = self if ContextAware === x
  x
end
end

....

Cheers

    robert


> In thinking Forth (http://thinking-forth.sourceforge.net/) Leo
> Brodie says that such a case should have the commonality extracted
> into an interface, each side talking to the interface in the way
> that is most suitable.  Then outsiders can get at the interface.
> [This is paraphrased from memory.  Oh, just a minute...]
> "Tip
> Both data structures and the commands involved in the communication
> of data
> between modules should be localized in an interface component."
> This means you can change the interface easily later.
>
> This begins to look like "model, view, controller" to me.
>
>>
>> I'll think on it some more though.
>> I take it you've looked at parser.rb then?
>
> Yes, it looks good but I've not got far with it yet.
>>
>> T.
>>
>         Hugh
>
>
>