In software engineering, double dispatch is a special form of multiple dispatch and a mechanism that dispatches a function call to different concrete functions depending on the runtime types of two objects involved in the call. In most OO systems, the concrete function that is called from a function call in the code depends on the dynamic type of a single object and therefore they are known as single dispatch calls, or simply virtual function calls.
Questions tagged [double-dispatch]
97 questions
68
votes
5 answers
Double dispatch in C#?
I have heard/read the term but don't quite understand what it means.
When should I use this technique and how would I use it? Can anyone provide a good code sample?

Oded
- 489,969
- 99
- 883
- 1,009
51
votes
5 answers
Difference betwen Visitor pattern & Double Dispatch
I am reading about visitor pattern, and it appears the same like Double Dispatch. Is there any difference between the two.
Do the two terms means the same thing.
reference: http://www.vincehuston.org/dp/visitor.html

vamsi
- 1,727
- 3
- 22
- 25
35
votes
7 answers
What's the difference between Polymorphism and Multiple Dispatch?
...or are they the same thing? I notice that each has its own Wikipedia entry: Polymorphism, Multiple Dispatch, but I'm having trouble seeing how the concepts differ.
Edit: And how does Overloading fit into all this?

raldi
- 21,344
- 33
- 76
- 86
22
votes
4 answers
How does double dispatch work in Visitor pattern?
I was looking into other questions related to the visitor pattern but couldn't understand the implementation of double dispatch in visitor pattern.
Please refer to the link
Visitor Pattern
How does double dispatch work in the Visitor pattern?

BOSS
- 2,931
- 8
- 28
- 53
22
votes
4 answers
Understanding double dispatch C++
I try to understand how double dispatch works. I created an example where a monster and a warrior derived from the abstract class Creature could fight. The class Creature has method "fight", which is defined in derived classes, and in each derived…

gartenzwerg
- 237
- 1
- 2
- 8
17
votes
2 answers
Java method overloading + double dispatch
Can anybody explain in detail the reason the overloaded method print(Parent parent) is invoked when working with Child instance in my test piece of code?
Any pecularities of virtual methods or methods overloading/resolution in Java involved…

Max
- 1,741
- 3
- 23
- 40
15
votes
5 answers
Polymorphically Dispatching in Java
In the following, I want EventHandler to handle EventA one way, EventB another way, and any other Events (EventC, EventD) yet another way. EventReceiver receives only a reference to an Event and calls EventHandler.handle(). The version that always…

user581638
- 223
- 3
- 8
14
votes
2 answers
What is Single and Double Dispatch?
i have wrote the visitor pattern as follow but i don't understand what is single and double dispatch.
AFAIK, single dispatch is invoke a method based on caller type where double dispatch is invoke a method based on caller type and argument type.
I…

nicholas
- 2,581
- 14
- 66
- 104
12
votes
4 answers
Double-dispatch and alternatives
I am trying to find a better way to handle some growing if constructs to handle classes of different types. These classes are, ultimately, wrappers around disparate value types (int, DateTime, etc) with some additional state information. So the…

redman
- 1,510
- 17
- 33
10
votes
4 answers
Double dispatch/multimethods in C++
I have a question on C++ double dispatch. In the code below, I want the results from the second set to match the results from the first set.
I don't know the actual type (unless I try dynamic_cast) but I do know that the object inherited from the…

cppalphadev
- 963
- 1
- 8
- 6
9
votes
5 answers
How to call the correct method in Scala/Java based the types of two objects without using a switch statement?
I am currently developing a game in Scala where I have a number of entities (e.g. GunBattery, Squadron, EnemyShip, EnemyFighter) that all inherit from a GameEntity class. Game entities broadcast things of interest to the game world and one another…

Michael
- 193
- 5
9
votes
5 answers
C++: doubts about visitor pattern
I know what Visitor Pattern is and how to use it; this question is not a duplicate of this one.
I've got a library where I put most of the reusable code I write, and which I link to most of my projects.
Often I need to add features to some classes,…

peoro
- 25,562
- 20
- 98
- 150
8
votes
6 answers
C++ Double Dispatch for Equals()
Imagine I have abstract base class Shape, with derived classes Circle and Rectangle.
class Shape {};
class Circle : public Shape {};
class Rectangle : public Shape {};
I need to determine if two shapes are equal, assuming I have two Shape*…

Adam Ernst
- 52,440
- 18
- 59
- 71
8
votes
5 answers
C++ double dispatch "extensible" without RTTI
Does anyone know a way to have double dispatch handled correctly in C++ without using RTTI and dynamic_cast<> and also a solution, in which the class hierarchy is extensible, that is the base class can be derived from further and its…

George Penn.
- 383
- 3
- 13
8
votes
1 answer
Visitor pattern where the visitors choose how to traverse
As I understand it, in the typical specification of the Visitor pattern, it is the visited objects that decide how to traverse, and generally, they only support one traversal order. (See, e.g., here or here.)
Is there a name for the same use of…

Joshua Goldberg
- 5,059
- 2
- 34
- 39