Re: When and where to use Visitor Pattern?
- From: "oldbull" <kai@xxxxxxxxxx>
- Date: 22 Apr 2005 10:18:39 -0700
I think visitor pattern is mostly used for allowing future extensions.
Suppose you have a data structure and want to add a new function by
traversing the data structure, you will have to add codes to varies
classes using your implementation. It may be error prone if your data
structure involves many classes.
Using the visitor pattern, such extension could be done by defining a
new visitor class. All codes related to the new function are localized
in the new visitor class. Thus, your code is easier to maintain.
I use visitor pattern a lot for traversing abstract syntax tree. If
you want to add some functions, it's quite straight forward. Although
it looks complicated at first.
.
- References:
- When and where to use Visitor Pattern?
- From: Sam Hwang
- When and where to use Visitor Pattern?
- Prev by Date: When and where to use Visitor Pattern?
- Next by Date: Re: Confusion about splitting classes to allow sharing of resources
- Previous by thread: When and where to use Visitor Pattern?
- Next by thread: Re: When and where to use Visitor Pattern?
- Index(es):