Thursday, December 14, 2006

Visitor Pattern : Java

I was trying to understand Visitor design pattern when I got into Single-dispatch and double-dispatch terms. Well, understanding of visitor pattern is enhanced once you understand the dispatch terminology in OOPs.

Single dispatch is a mechanism where a function call on an object is rightly dispatched to correct method based on the type of the object. The arguments of function call do not really matters. However, in a double dispatch mechnism, a function call is dispatched to different concrete functions depending on the runtime types of multiple objects involved in the call. Java does support single dispatch mechsnism. However, there is MultiJava compiler written to take of double dispatch mechanism. Check out a nice simple reading on dispatch definition, http://ifacethoughts.net/2006/07/29/single-double-and-multiple-dispatch/


The link http://rileywhite.com/software/visitorpattern.html  presents nice explanation on the visitor pattern. One thing is sure. Visitor pattern is definitely hard to learn, unlike adapter, observer, factory patterns which are intuitive and widely used.

Another great reading on visitor pattern, which I really loved, is http://www.javaworld.com/javaworld/javatips/jw-javatip98.html .

Definition: The Visitor pattern lets us define a new operation on an object structure without changing the classes of the objects on which it operates. Rather than writing dedicated methods for each programming task and afterwards recompiling, the idea is to (1) insert a so-called accept method in each class, and (2) write the action code in so-called visitors.

One example code for visitor pattern is http://bobcat.webappcabaret.net/javachina/jc/ptn/Visitor.htm


2 Comments:

Blogger sharry s said...

Hi,

Thanks for sharing these information with us its rally very helpful.
D Brain songs mp3 downloads

8:37 AM  
Blogger saiful Islam said...

Hi,

Blog Programming favorite tutorial and websites of the internet on your browser. My site is learning many tutorial & online earning. so my site share you friends If you want to earn money to sit on your home, you can follow my site http://freelancetube.blogspot.com/

I have listed there a lot of Photoshop and Illustrator tutorials, Earning Tutorials, etc. There will not any hamper for you to visit my site rather you will be benefited.

http://freelancetube.blogspot.com/

6:18 PM  

Post a Comment

<< Home