According to GOF [1], 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 ….

References:

  1. Erich Gamma, Richard Helm, Ralph Johnson, John Vlissides (1994). Design Patterns: Elements of Reusable Object-Oriented Software. Addison Wesley.  ISBN  0-201-63361-2
  2. https://en.wikipedia.org/wiki/Visitor_pattern
  3. https://sourcemaking.com/design_patterns/visitor
  4. http://www.oodesign.com/visitor-pattern.html
  5. http://www.dofactory.com/net/visitor-design-pattern
Advertisements