Re: When and where to use Visitor Pattern?



"Sam Hwang" <samhng@xxxxxxxxx> wrote:

>Hello,
>I am confused about Visiotr Pattern. Observe this example from
>nice.sf.net:
>
...
>}
>I dont know in what cirumstances the pattern is used sensablely. I hope
>someone can address my confusion. Thanks!
>

The problem with Visitor is than it can easily be overused. Take any
class hierachy, equip it with the Visitor pattern (i.e. create the
MyHierarchyVisitor interface with all the relevant visit(...) methods
and add the accept(MyHierarchyVisitor) method to all your classes) and
then, you can "externalize" all code in you hierarchy into visitors.
Then in you hierarchy remains nothing but data structure, no behaviour
anymore.

The key for proper use of Visitor is to stick with the
"Responsibility" philosophy (as in the CRC approach) : the behaviour
that remains in your classes should be the implementation of their
core responsibilities. Everything else can be externalized through the
use of Visitor.

.



Relevant Pages

  • Re: Pentatonic scale issue
    ... in article 44b73850$0$15011$88260bb3@xxxxxxxxxxxxxxxxx, John B at ... Sorry for the confusion. ... It's not about "starting" on any pattern. ... Learn the shapes individually a couple at a time. ...
    (alt.guitar.beginner)
  • Re: BOZ-literal-constant conversion?
    ... > no integer around - just the bit pattern and the real. ... > standard describes the syntax for BOZ as an integer literal constant - ... transferring the bit pattern), this of course there will be ... confusion about the meaning of REAL. ...
    (comp.lang.fortran)
  • Re: Synchronous siteswaps and rhythm
    ... I'm still trying to wrap my head around siteswaps, ... ball shower, for example. ... i.e. the "rhythm" of the pattern. ... confusion as to whether we are skipping a beat or not, like is ...
    (rec.juggling)
  • Re: Pentatonic scale issue
    ... Sorry for the confusion. ... Hi John, It's my understanding that they are saying that's ... It's not about "starting" on any pattern. ... It takes a lot of practice to get it. ...
    (alt.guitar.beginner)
  • Re: NHPs produced without CD
    ... that display the same pattern without common descent. ... "The fractal hierarchy is evidently the least-energy pathway to ... What makes it a "tree" exactly? ...
    (talk.origins)