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
1
vote
1 answer

Downcasting using a non-virtual interface along a template class

I am implementing a finite element code. Problem description In finite element methods, we need an integrator and an interpolator. An integrator is an object that performs numerical integration on a geometrical object, for example, a quadrilateral,…
1
vote
1 answer

Means of copying derived class attributes without dynamic casting

I am trying to find an efficient way (using polymorphism) to copy specific attributes between two derived classes externally. I have a set of data classes that derive from a base class DataClassA. I want to operate on these data classes in a…
1
vote
2 answers

C++ Polymorphic Circular depenencies with double dispatch

So, I'm having a big issue with circular dependency. My Square.h and Circle.h classes both inherit Shape.h, and use double dispatch in order to try and detect collision between the two. My classes are currently setup in the following sort of…
1
vote
2 answers

Implementing a double dispatch in C# extensible for both functions and objects to operate on

I'm looking for a way to implement a double dispatch that can be extended for both methods and classes. Until now I used basically three approaches: the traditional procedural approach with a great switch (easy to add new functions, hard to add new…
Onur
  • 5,017
  • 5
  • 38
  • 54
1
vote
1 answer

Most Pythonic double dispatch for extracting View information from Model

I'm coding a desktop app with Python and Qt, using PySide. I need to display a tree view in which top-level items are objects of different type than their children. Specifically, a top-level item is a Git repository, whereas its children are…
Vojislav Stojkovic
  • 8,043
  • 4
  • 35
  • 48
1
vote
0 answers

Double Dispatch

Possible Duplicate: Double dispatch in C#? Can somebody explain what is the Double Dispatch pattern in detail with a simple example in C#? I know there are already some questions about this topic on SO, but I dont understand the sense of the…
Rookian
  • 19,841
  • 28
  • 110
  • 180
0
votes
2 answers

How to get concrete type from mapping variable?

I have the following code: const enum ShapeType { Circle, Rectangle } class Shape { constructor(public shapeType: ShapeType) {} } class Circle extends Shape { constructor(public x: number, public y: number, public r: number) { …
Ryan Peschel
  • 11,087
  • 19
  • 74
  • 136
0
votes
1 answer

`vec_arith` double dispatch error with packages

I'm trying to implement the vctrs package, but specifically I'm trying to get the vec_arith double dispatch working. The example code below works if I load this into the global environment, however it does not seem to find the correct dispatch if…
Justin Landis
  • 1,981
  • 7
  • 9
0
votes
1 answer

Forward declaring class with templated code

I'm trying to implement the double dispatch pattern for a message interface in C++. However, I find that I have to be too verbose in my handler class due to having to forward declare each message. I'm looking for a way to structure the file(s) to be…
0
votes
1 answer

Passing shared_ptr as shared_ptr

I currently have the following structure class A class B : public A class C : public A I have virtual methods defined in A and B and C are overriding them. The methods are of the sort bool C::CheckCollision(shared_ptr box); bool…
0
votes
1 answer

How to call function dynamically with polymorphism argument

How can I dinamcally call function of the form:childA.function(childB) while their static types are both of the parents? and with more details: I have a physics project where I need to calculate the potential of 2 molecules. But I have 2 types of…
pio
  • 500
  • 5
  • 12
0
votes
1 answer

Why is an infinite loop not caused by Java double dispatch?

In lectures we were shown this code and told that it creates double dispatch but why does it not create an infinite loop? If c3po.greet(c4po); calls the TranslationRobot method from TranslationRobot Why does c5po.greet(c4po); call the AbstractRobot…
Tristan Warren
  • 435
  • 1
  • 7
  • 17
0
votes
1 answer

Double Dispatch when having a method that accepts Object class

I have an Implementation of a Mapper class which accepts Object as parameter in one of the map(Object object) functions. The rest map(T t) functions accept Integer or Class etc. When I try to pass an int it gets Autoboxed into Integer and invokes…
Pavlos
  • 2,183
  • 2
  • 20
  • 27
0
votes
1 answer

Polymorphic uncurried method calls (adhoc polymorphism) in Java

Let me start with an example. Say I have an abstract Vehicle class. public abstract class Vehicle { public Vehicle() {} public abstract void ride(); } And classes Car and Bicycle that inherit from this abstract class. public class Car…
0
votes
2 answers

Double dispatch and factory pattern

I've got the following code currently (not working): #include #include class Circle; class Rectangle; class Shape { private: Shape() {}; public: virtual ~Shape() {}; friend class Circle; friend class…
greywolf82
  • 21,813
  • 18
  • 54
  • 108