Re: When and where to use Visitor Pattern?



<Nicholls.Mark@xxxxxxxxx> wrote in message
news:1114618156.808945.16930@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

>
> if 'instanceof' is some form of reflection,

It's dynamic type checking, querying for the existence of interfaces, I
don't think you would call that reflection.

> then there are plenty of
> people (well at least me) who prefer the type safety of visitors....in
> fact in some sense I view visitors as typesafe reflection.
>
As typesafe casting, perhaps? Without the runtime cost of an instanceof or
typeof? I do agree with this characterization, I think it's correct.

But there's not really a material difference between the two approaches,
apart from matters of clarity. In both cases you have to enumerate all the
types of interest, and using instanceof/typeof is type safe.

> less clutter? I don't think that the visit method is particularly
> prohibitive in terms of clutter, though I accept that visitors can
> fracture your code into tiny itty bitty bits.
>
Yeah, I guess my main issue is that I find code written to the visitor
pattern to be less clear than code written in alternative styles, and I have
to confess to having a distaste for "tiny itty bitty bits".

Regards,
Daniel Parker


.



Relevant Pages

  • Re: Is instanceof dirty?
    ... If you use instanceof then you are ... You can think of 'instanceof' as a specific kind of reflection. ... but at the cost that /you/ have taken over responsibility ... almost certainly creating an ugly mess of hacks. ...
    (comp.lang.java.programmer)
  • Re: When and where to use Visitor Pattern?
    ... if 'instanceof' is some form of reflection, then there are plenty of ... people who prefer the type safety of visitors....in ... fact in some sense I view visitors as typesafe reflection. ... prohibitive in terms of clutter, though I accept that visitors can ...
    (comp.object)