On Fri, 28 Jan 2005, Trans wrote:

> Good point. Fortunately these classes are all self contained beyond
> being subclasses of Marker.
>
> The reason has to do with some trouble I alsways seem to run into with
> these types of apps. Basically I have a Parser instance that gets fed
> Token classes (Markers) which contain class level information on how to
> recognize the relavent text they will parse. Here a very simple
> example:
         [...]
>
> registry = Parser::Registry.new
> registry.register( XmlTagToken )
> registry.register( XmlEntityToken )
>
> cp = Parser.new( registry )
> d = cp.parse( s )
> y d
>
> The I take this further and add instance methods to the tokens to parse
> sepecialize content. Sometimes that content is "reentrant", that is to
> say I need to reparse it --like an embedded document.
>
> So the problem? How do I talk to my Parser instance from within an
> instance of a Token?

I think you need the Token to be aware of the Parser, as well as the
Parser being aware of the Token.  You need to pass the one to the
other in both cases.

If I have anything like a grasp on the topic of the rest of this
sentence, then Dependency Injection may be of use here.  I think
D.I. can work like a Personal Assistant, so /s?he/ tells the
colleague classes to arrange the meeting you want to have.
All the arrangements are done through /h(im|er)/, so you don't have
to worry about the details.

I might have this wrong, and it might be Model, View, Controller
that is needed here, because the controller mediates between the
Model and the View.  This would suggest that the ownership
relationship is not really a factor in this communication problem,
except in so far as it is where the problem arises.  The analogy
might be better expressed as "Bosses can get on better with Workers
if there is a Union committed to doing something mutually beneficial
where possible", but this is probably stretching things...!

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.

>
> If you have an elgant solution to that I'll give you more than a
> pat on the back!
>
> T.
>
         Hugh
>
>