Questions tagged [double-dispatch]

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.

97 questions
7
votes
1 answer

Double dispatch in Pharo

Could someone please explain the process of double dispatch in Pharo 4.0 with Smalltalk? I am new to Smalltalk and am having difficulty grasping the concept, since it is implemented very differently in Java as compared to Smalltalk. It will be very…
ruhi
  • 73
  • 3
7
votes
3 answers

I need to ask about the object class, but it's a bad practice. Alternatives for this case?

I'm having trouble extending an application. It is an attendance record system. Currently each employee records attendance by a card that has a QR code. Now they want to add fingerprint recognition, and there was no problem until they asked for two…
gal007
  • 6,911
  • 8
  • 47
  • 70
6
votes
3 answers

Two-way extensible hierarchy with Java

My question is about implementing different behaviours for different messages in an as extensible way as possible. I am aware of the visitor pattern, I am aware of double-dispatch, but I can't seem to figure out a solution, which satiesfies me (not…
midor
  • 5,487
  • 2
  • 23
  • 52
6
votes
4 answers

Double dispatch and template class

I have a C++ code where I compare different class deriving from a common mother class, Foo. If the two class have not the same type, the comparison is always false. Otherwise, it compares some internal data specific to the class. My code looks like…
Dr_Sam
  • 1,818
  • 18
  • 24
5
votes
2 answers

(Nested?) Multiple Dispatch [Visitor Pattern]

I've come to a road block in my application architecture. I've just started using the visitor pattern to execute specific algos on abstract objects of which type I don't know at runtime. My problem is that my algo also depends on the type of a…
5
votes
2 answers

Trying to use templates to double dispatch physics collision

I want to let the compiler build the connections of functions for a physics collision system. I have the test collision function: template inline void Collision(T& t, U& u) { if(u.CheckCollision(t.GetCollider())) { …
Tavison
  • 1,523
  • 1
  • 11
  • 19
5
votes
2 answers

visitor-like pattern for template objects

I’m trying to make a custom collision engine for academic purposes and i'm stuck on a general c++ programming issue I already have all the geometries which work properly and for the scope of the question i have this function: template
tiridactil
  • 389
  • 1
  • 11
5
votes
1 answer

Visitor Pattern in C++ with multiple visitable parameters

Consider the following hierarchy: class Base { virtual void Method() = 0; virtual void Accept(Visitor *iVisitor) = 0; }; class Derived1: public Base { virtual void Method(){//impl} virtual void Accept(Visitor *iVisitor) { …
Heisenbug
  • 38,762
  • 28
  • 132
  • 190
4
votes
1 answer

Why we need accept() in Visitor pattern and why we cannot call visitor.visit() directly?

I am revising the Visitor pattern I used some time ago. We have base class Element which has virtual method accept(Visitor) and this method is overridden in all classes inheriting from Element. And all that accept() does in any derived class is to…
Andrey Rubliov
  • 1,359
  • 2
  • 17
  • 24
4
votes
2 answers

Visitor and double dispatch without overriding "accept" method in c++

Ok: here´s my problem: I have a base composit class which accepts a visitor an then iterates over its nodes. Works like a charm. But then, I have to used a derived from this composit and recognized that I have to override the "accept()" method in…
4
votes
2 answers

C++ type comparison: typeid vs double dispatch dynamic_cast

Are there any performance or robustness reasons to prefer one over the other? #include #include struct B { virtual bool IsType(B const * b) const { return IsType2nd(b) && b->IsType2nd(this); } virtual bool IsType2nd(B…
ThomasMcLeod
  • 7,603
  • 4
  • 42
  • 80
4
votes
4 answers

c++ double dispatch with mirrored hierarchies

the following class hierarchies represent abstract resource handler and resource hierarchies. Both have the interfaces as base classes. Now imagine you write a system where you can implement multiple specific resource systems under these interfaces.…
4
votes
2 answers

Double Dispatch automatization in Java

I have two interfaces Query and Filter(Query is a class in example for simplification, I have 1 query for now) , I now want write function Query.applyFilter() depending on what Filter is real is i.e different functions for NameFilter and DateFilter…
RiaD
  • 46,822
  • 11
  • 79
  • 123
4
votes
3 answers

Separation of algorithms and data in a geometry library (triple-dispatching needed?)

I am having trouble designing the part of my application that deals with geometry. In particular, I would like to have a hierarchy of classes and separate methods for intersections. The problem The hierarchy would be something like…
jmeseguerdepaz
  • 332
  • 2
  • 7
3
votes
0 answers

call non-virtual method of derived class in polymorphic hierarchy of library that can't be modified without down-casting

Today interviewer told me that Visitor pattern & double dispatch can be used to call non-virtual method of derived class from 3rd party library which source code can't be accessed/changed (this is what they do in their production code, he said). For…
Soup Endless
  • 439
  • 3
  • 10