According to GOF , Visitor pattern is:
“Represent an operation to be performed on elements of an object structure. Visitor lets you define a new operation without changing the classes of the elements on which it operates.”
If we spend some time on Visitor pattern, we sooner or later will realize that the real purpose behind Visitor pattern is to separate operations from objects. If we don’t just satisfy with our current understanding and look further to the horizon for a deeper understanding, what do we find?
Here is my 2c.
What if we apply this Visitor pattern to database, let database tables to be the “objects”, we then can write queries and commands as the “operations” against the “objects”. Is this a wilder application of Visitor pattern?
Can you find an even wilder application of Visitor pattern? Let me know ….
- Erich Gamma, Richard Helm, Ralph Johnson, John Vlissides (1994). Design Patterns: Elements of Reusable Object-Oriented Software. Addison Wesley. ISBN 0-201-63361-2