There is indeed. Drop the name "double dispatch" in Google and find some examples. Say a method gets a parameter declared as an abstract type. The actual parameter might be any subclass. Say the method has to take different action for each subclass. It might have a case statement
testing for instanceof every known subclass. Big switch statement, can't handle new subclasses.
So in double dispatch, the parameter objects would know what to do differently. So our method just calls the parameter object passing itself, and the parameter object does the work.
Did you find that confusing? Me, too! Look around for some concrete examples and see if they make more sense.
The classic example is numbers. Say I have an Int class (not talking real
Java now) with an "add" operator. a.add(b) gives a+b. The add method might check b to see if it's an int, float, double, etc. With double dispatch it could say b.addInt(self). Int, Float, Double, etc. would all have addInt() methods that do the proper casting or conversions or whatever is needed. No case statement!
[ April 30, 2003: Message edited by: Stan James ]