Re: When and where to use Visitor Pattern?
- From: Remi Bastide <FirstName.LastName@xxxxxxx>
- Date: Sat, 23 Apr 2005 16:04:06 +0200
"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.
.
- References:
- When and where to use Visitor Pattern?
- From: Sam Hwang
- When and where to use Visitor Pattern?
- Prev by Date: Re: When and where to use Visitor Pattern?
- Next by Date: Re: audit log on normalized data
- Previous by thread: Re: When and where to use Visitor Pattern?
- Next by thread: Re: When and where to use Visitor Pattern?
- Index(es):
Relevant Pages
|