CSC/ECE 517 Fall 2012/ch2b 2w51 aa: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
No edit summary
 
(67 intermediate revisions by 2 users not shown)
Line 1: Line 1:
=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==
==Introduction==
In Object Oriented Programming, visitor pattern is a way of decoupling algorithms to be performed by an object. The way to do this is 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 implements the algorithm using double dispatch.
In Object Oriented Programming <ref>[http://en.wikipedia.org/wiki/Object-oriented_programming<i>Object Oriented Programming </i>]</ref>, 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.


* http://kasunpanorama.blogspot.com/2010/04/understanding-visitor-pattern.html This page can provide more introductory information on visitor pattern
For more information on the Visitor pattern, you can visit the following links
*[http://kasunpanorama.blogspot.com/2010/04/understanding-visitor-pattern.html Kasunpanorama Blogspot] This page can provide more introductory information on visitor pattern
 
*[http://en.wikipedia.org/wiki/Visitor_pattern  Wikipedia Visitor Pattern] : Wikipedia provides a good condensed view on the topic of the Visitor Pattern.


==Motivation==
==Motivation==
* http://en.wikipedia.org/wiki/Visitor_pattern - Motivation for visitor patterns is nicely depicted in Wikipedia for Visitor pattern.


* http://www.oodesign.com/visitor-pattern.html - One of the top visited sites for design pattern basics to implementation, oodesign.com has good introduction, implementation details.
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


* http://sourcemaking.com/design_patterns/visitor This page has good detailed description of visitor pattern and the worth reading part is the discussion section of this page which also talks about how double dispatch is related to visitor.
* [http://en.wikipedia.org/wiki/Visitor_pattern Wikipedia Visitor Pattern]Motivation for visitor patterns is nicely depicted in Wikipedia for Visitor pattern.
 
* [http://www.oodesign.com/visitor-pattern.html Oodesign] One of the top visited sites for design pattern basics , oodesign.com has good introduction, examples and implementation details. Sample code is also available for the reader. The article is good not only from the point of view of explaining the motivation behind Visitor patterns, but also because it follows a good flow in setting up the topic, explanation using examples and concluding with a brief summary
 
* [http://sourcemaking.com/design_patterns/visitor SourceMaking] This page has good detailed description of visitor pattern and the worth reading part is the discussion section of this page which also talks about how double dispatch is related to visitor<ref>[http://sourcemaking.com/design_patterns/visitor<i>SourceMaking</i>]</ref>..
 
* [http://www.dofactory.com/Patterns/PatternVisitor.aspx DoFactory] Simple introductory page which describes and talks about the pattern in short. It is a very 'bare-bones' reference article, but is a good introductory piece


* http://www.dofactory.com/Patterns/PatternVisitor.aspx - Simple introductory page which describes and talks about the pattern in short.
==Visitor Pattern in Java==
==Visitor Pattern in Java==
(1) http://java.dzone.com/articles/design-patterns-visitor
(2) http://www.javaworld.com/javatips/jw-javatip98.html
(3) http://snehaprashant.blogspot.com/2009/01/visitor-pattern-in-java.html
(4) http://en.wikipedia.org/wiki/Visitor_pattern#Java_example


==Visitor Pattern in C++==
Following are the links which provides examples based on C++:


* http://sourcemaking.com/design_patterns/visitor/cpp/1
* [http://java.dzone.com/articles/design-patterns-visitor DZone] The article explains the use of the Visitor pattern in Java. A real world analogy is given initially and then Java implementation of a Visitor pattern is explained. The author maintains a good flow and then concludes with a mention of few disadvantages of the pattern.
 
* [http://www.javaworld.com/javatips/jw-javatip98.html JavaWorld] This article provides a very detailed example of a Visitor pattern implementation in Java. The author guides the reader through each step, explaining the process as he goes along.
 
* [http://snehaprashant.blogspot.com/2009/01/visitor-pattern-in-java.html Snehaprashant Blogspot] The article starts of by providing a brief description of the pattern, it's advantages and disadvantages and then provides a detailed example of the Visitor pattern. The flow is good and the code example is good, but the explanation of the code is not provided. However the code is quite self explanatory.
 
* [http://en.wikipedia.org/wiki/Visitor_pattern#Java_example Wikipedia Visitor Pattern] Another good example of the Java implementation obtained from Wikipedia.
 
===Drawback===
1. [http://snehaprashant.blogspot.com/2009/01/visitor-pattern-in-java.html Snehaprashant Blogspot] does not provide explanation of the code example.


* http://sourcemaking.com/design_patterns/visitor/cpp/3
==Visitor Pattern in C++==
Following are the links which provide examples based on C++:


* http://sourcemaking.com/design_patterns/visitor/cpp/2
*[http://sourcemaking.com/design_patterns/visitor/cpp/1 SourceMaking Example 1]  A comparison is provided between the 'before' and 'after' code based on the Visitor pattern implementation. This link and the next couple of links are part of the same discussion provided in [http://sourcemaking.com/design_patterns/visitor SourceMaking].
* [http://sourcemaking.com/design_patterns/visitor/cpp/2 SourceMaking Example 2]
* [http://sourcemaking.com/design_patterns/visitor/cpp/3 SourceMaking Example 3]
* [http://www.swe.uni-linz.ac.at/research/deco/designPatterns/visitor/visitor.defaultroles.c++.html Software Engineering group] This page explains visitor pattern in detail from the basics till implementation using C++. It has implementation details and also discusses issues that could possibly arise when using the Visitor pattern. This page provides good code example in C++ along with detailed explanation. This page overcomes the drawback of [http://sourcemaking.com/design_patterns/visitor SourceMaking].


* This page explains visitor pattern in detail from the basics upto implementation using C++ as language. It has implementation details and also have discussed issues that arise. http://www.swe.uni-linz.ac.at/research/deco/designPatterns/visitor/visitor.defaultroles.c++.html
===Drawback===
1. Good code in [http://sourcemaking.com/design_patterns/visitor 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==
==Visitor Pattern in Python==
Following are two links which provide good examples of implementation of visitor patterns in python:
Following are two links which provide good examples of implementation of visitor patterns in python:


* https://chris-lamb.co.uk/2006/12/08/visitor-pattern-in-python/
* [https://chris-lamb.co.uk/2006/12/08/visitor-pattern-in-python/ Lamby Blog] The author sets up the explanation by using the example of an Abstract syntax tree traversal. A brief comparison is also provided about the differences in a Java implementation and a Python implementation for the same.
 
* [http://curtis.schlak.com/2012/01/04/python-visitor-pattern-helper.html Curtis] The author presents a similar example as the link before.
===Drawback===
1. [https://chris-lamb.co.uk/2006/12/08/visitor-pattern-in-python/ Lamby Blog] is not well organized and no detailed discussion about the code he provided.


* http://curtis.schlak.com/2012/01/04/python-visitor-pattern-helper.html
2. A point to note about [http://curtis.schlak.com/2012/01/04/python-visitor-pattern-helper.html 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==
==Visitor Pattern in Ruby==
(1) https://gist.github.com/989193
Following are the links which provide examples based on Ruby
(2) http://www.scribd.com/doc/2217773/Design-Patterns-in-Ruby
 
*[http://www.scribd.com/doc/2217773/Design-Patterns-in-Ruby Scribd ] This link provides a good discussion about all design patterns including the Visitor pattern. Implementation is done in Ruby and there are sufficient code examples.
 
*[https://gist.github.com/989193 Gist Github] This link provides a singular example of Ruby implementation of the Visitor pattern.
 
===Drawback===
1. In [https://gist.github.com/989193 Gist Github] only code is available and no explanation is provided because of nature of the site.


==Advantages==
==Advantages==
* This links helps to understand the advantage of a design pattern like visitor, which are the features it combines and how it makes it easy for programmer to implement those ideas. http://compilers.cs.ucla.edu/jtb/jtb-2003/whyvisitors/whyvisitors.html
* [http://compilers.cs.ucla.edu/jtb/jtb-2003/whyvisitors/whyvisitors.html UCLA CS] helps to understand the advantage of a design pattern like visitor, which are the features it combines and how it makes it easy for programmer to implement those ideas.  


* The applicability of visitor pattern can be found here: http://www.swe.uni-linz.ac.at/research/deco/designPatterns/visitor/visitor.abstract.html#Applicability
* [http://www.swe.uni-linz.ac.at/research/deco/designPatterns/visitor/visitor.abstract.html#Applicability Software Engineering group]The applicability of visitor pattern can be found on this page.


==Disadvantages==
==Disadvantages==
* http://www.developerfusion.com/article/84939/iterators-composites-and-visitors/ This page has a subsection in the visitor pattern section which discusses issues related to visitor pattern.  
* [http://www.developerfusion.com/article/84939/iterators-composites-and-visitors/ DeveloperFusion]has a subsection in the visitor pattern section which discusses issues related to visitor pattern.  
 
* [http://www.oodesign.com/visitor-pattern.html Oodesign] describes issues with visitor pattern in section Specific problems and implementation<ref>[http://www.oodesign.com/visitor-pattern.html<i> Oodesign</i>]</ref>.
 
==Conclusion==


* http://www.oodesign.com/visitor-pattern.html This page describes issues with visitor pattern in section Specific problems and implementation
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 [http://programmers.stackexchange.com/questions/48811/what-design-patterns-are-the-worst-or-most-narrowly-defined 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<ref>[http://en.wikipedia.org/wiki/Visitor_pattern<i>Visitor Pattern </i>]</ref>.


=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.


Video Lecture:
=References=
(1) https://www.youtube.com/watch?v=mTJodk3vfdk
<references>
(2) https://www.youtube.com/watch?v=UYUopyMcWjw&feature=related

Latest revision as of 01:42, 29 November 2012

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 <ref>Object Oriented Programming </ref>, 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

  • Oodesign One of the top visited sites for design pattern basics , oodesign.com has good introduction, examples and implementation details. Sample code is also available for the reader. The article is good not only from the point of view of explaining the motivation behind Visitor patterns, but also because it follows a good flow in setting up the topic, explanation using examples and concluding with a brief summary
  • SourceMaking This page has good detailed description of visitor pattern and the worth reading part is the discussion section of this page which also talks about how double dispatch is related to visitor<ref>SourceMaking</ref>..
  • DoFactory Simple introductory page which describes and talks about the pattern in short. It is a very 'bare-bones' reference article, but is a good introductory piece

Visitor Pattern in Java

  • DZone The article explains the use of the Visitor pattern in Java. A real world analogy is given initially and then Java implementation of a Visitor pattern is explained. The author maintains a good flow and then concludes with a mention of few disadvantages of the pattern.
  • JavaWorld This article provides a very detailed example of a Visitor pattern implementation in Java. The author guides the reader through each step, explaining the process as he goes along.
  • Snehaprashant Blogspot The article starts of by providing a brief description of the pattern, it's advantages and disadvantages and then provides a detailed example of the Visitor pattern. The flow is good and the code example is good, but the explanation of the code is not provided. However the code is quite self explanatory.

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++:

  • SourceMaking Example 1 A comparison is provided between the 'before' and 'after' code based on the Visitor pattern implementation. This link and the next couple of links are part of the same discussion provided in SourceMaking.
  • SourceMaking Example 2
  • SourceMaking Example 3
  • Software Engineering group This page explains visitor pattern in detail from the basics till implementation using C++. It has implementation details and also discusses issues that could possibly arise when using the Visitor pattern. This page provides good code example in C++ along with detailed explanation. This page overcomes the drawback of SourceMaking.

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:

  • Lamby Blog The author sets up the explanation by using the example of an Abstract syntax tree traversal. A brief comparison is also provided about the differences in a Java implementation and a Python implementation for the same.
  • Curtis The author presents a similar example as the link before.

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

  • Scribd This link provides a good discussion about all design patterns including the Visitor pattern. Implementation is done in Ruby and there are sufficient code examples.
  • Gist Github This link provides a singular example of Ruby implementation of the Visitor pattern.

Drawback

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

Advantages

  • UCLA CS helps to understand the advantage of a design pattern like visitor, which are the features it combines and how it makes it easy for programmer to implement those ideas.

Disadvantages

  • DeveloperFusionhas a subsection in the visitor pattern section which discusses issues related to visitor pattern.
  • Oodesign describes issues with visitor pattern in section Specific problems and implementation<ref> Oodesign</ref>.

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<ref>Visitor Pattern </ref>.

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

<references>