Reputation: 27219
GoF book on Design pattern says this about the Visitor
pattern :
Visitor lets you define a new operation without changing the classes of the elements on which it operates.
I read the pattern from that book but failing to understand the intuition behind naming this pattern Visitor
. Why is it called Visitor
?
Upvotes: 0
Views: 275
Reputation: 1881
There is this popular french expression/joke : "Fais comme chez toi mais n'oublie pas que tu es chez moi" which i would translate "Make yourself at home, but don't forget that it is my home".
I think it would be hard to tell exactly what was in mind of people who originally named the pattern this way, but i think that intuitively it is the similarity with the "Hospitality" concept.
Classes can give access from their public methods (a door ?) to a Visitor. The thing is that, rather than trying to take specific actions depending on who is the Visitor/guest, the class will simply delegate the appropriate behavior to take to the Visitor (Make yourself home...). That is, the Visitor will use for that the public behavior of its Host class (don't forget that it is my home ...).
Upvotes: 3