[Tutor] Visitor Pattern
Sean 'Shaleh' Perry
shaleh at speakeasy.net
Fri Feb 6 00:38:06 EST 2004
On Sunday 01 February 2004 18:05, Daniel Ehrenberg wrote:
> What is a visitor pattern? I've heard that it shows
> how good a language is, and that Lisp is really good
> because it can be done in two (cryptic) lines. How can
> a visitor pattern be implimented in Python?
It is from the original "Desgin Patterns" book which is one of the bibles of
Represent an operation to be performed on the elements of an object structure.
Visitor lets you define a new operation without changing the class of the
elements on which it operates.
The idea here is you have an object with "visits" another object and in some
way interacts with it.
for window in windowList:
which in functional terms shows up as:
or in new terms
[display.draw(window) for window in windowList]
Visitor is a very, very common idiom in functional languages.
More information about the Tutor