CSC/ECE 517 Fall 2012/ch2b 2w51 aa

From PG_Wiki
Jump to: navigation, search

Contents

Visitor Pattern, Directory of sites

The Purpose of this article is to act as a "directory of sites", or a simple quick jump page for the reader. The effort is to try and collect good sources (blog posts, forum chats, general articles etc.) which deal with the Visitor pattern and to make this available to the readers with summary. The readers can then explore the links provided, to understand certain topics that they are interested in. Readers are also encouraged to edit the document in case they are able to contribute good material. Since this is just a quick jump page, there will be an apparent lack of examples. This is in line with the requirements given in the writeup, since we are re-directing you to pages where you will get plenty of information.

Introduction

In Object Oriented Programming [1], the Visitor Pattern is a way of decoupling algorithms to be performed by an object. The way to do this is to create a visitor class which would help to add new virtual function to the classes without modifying their structures. This is accomplished by creating appropriate specializations of the virtual function in visitor class which will take instance reference as input and implement the algorithm using double dispatch.

For more information on the Visitor pattern, you can visit the following links

Motivation

Now that some information is present about what the Visitor pattern is and what it should do, let us explore the motivation behind using the Visitor pattern. Some links are provided for the reader to explore the topic and a brief summary is presented to guide the reader

Visitor Pattern in Java

Drawback

1. Snehaprashant Blogspot does not provide explanation of the code example.

Visitor Pattern in C++

Following are the links which provide examples based on C++:

Drawback

1. Good code in SourceMaking but lack of proper explanations to the code. If the reader has no prior knowledge about visitor pattern then it is difficult to understand this code.

Visitor Pattern in Python

Following are two links which provide good examples of implementation of visitor patterns in python:

Drawback

1. Lamby Blog is not well organized and no detailed discussion about the code he provided.

2. A point to note about Curtis is that there is sufficient amount of code, but not enough explanation. However, the code is still useful with prior knowledge of visitor pattern.

Visitor Pattern in Ruby

Following are the links which provide examples based on Ruby

Drawback

1. In Gist Github only code is available and no explanation is provided because of nature of the site.

Advantages

Disadvantages

Conclusion

In search of websites/blogs related to visitor pattern one will realize that very few websites/blogs are available for this design pattern and it appears to be have most narrow use. One can find some sites/discussion forums which debate on whether design pattern like visitor add complexity to the code, one such can be found here Programmers Stackexchange. The definition of this pattern is very clear "separation of algorithms" from an object so as to make later modifications(addition) easy and with no need to change structure of class. The pattern can find good usage in a scenario where the object classes rarely change but one needs to define new operations on the object[4].

Links to Video Tutorials

1. https://www.youtube.com/watch?v=mTJodk3vfdk This video provides a brief explanation of the motivation behind Visitor patterns, an example, a simple UML diagram for the pattern and mentions advantages of using the pattern.

2. https://www.youtube.com/watch?v=UYUopyMcWjw This video is similar to the example before, but provides a sample Java implementation as well.

References

  1. Object Oriented Programming
  2. SourceMaking
  3. Oodesign
  4. Visitor Pattern
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox