Skip to main content

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.

double-dispatch
3 votes
0 answers
72 views

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 ...
Soup  Endless's user avatar
3 votes
1 answer
356 views

Visitor Pattern and Double Dispatch

I know this is well trodden territory but I have a specific question... I promise. Having spent very little time in the statically typed, object oriented world, I recently came across this design ...
Solaxun's user avatar
  • 2,762
0 votes
2 answers
376 views

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, ...
Ryan Peschel's user avatar
  • 11.7k
1 vote
1 answer
96 views

Double dispatch using visitor pattern in Java

I have this architecture: In XMLFormulaFormatter, I need the value of instances of Constant (instances which are created in my Main class). I have this method in the Constant class: public double ...
kAmJi's user avatar
  • 97
0 votes
1 answer
362 views

`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 ...
Justin Landis's user avatar
1 vote
2 answers
322 views

How to use a Double Dispatch with compareTo in JAVA?

A beginner of Java... I'm a bit confused by how to apply double dispatch (and visitor pattern) together with the compareTo method in JAVA. Example Scenario: Let's say I have an Animal interface where ...
user140536's user avatar
1 vote
1 answer
236 views

Wrong double dispatch method when putting a vctrs-built class in a package

I've created a new class to print percentages with vctrs, like explained in https://vctrs.r-lib.org/articles/s3-vector.html . It works well when I source the .R file. But when I build the package with ...
Brice Nocenti's user avatar
2 votes
0 answers
69 views

Double dispatch in R: S4 vs vctrs library [closed]

If we want to implement a double dispatch method in R, we currently have two options to choose from: S4 methods vctrs library S3-based double dispatch I especially mean arithmetic operators, such as ...
KrzJoa's user avatar
  • 71
1 vote
1 answer
251 views

How is an "isa?" based multimethod more than syntax sugar for instanceof?

I am taking an example from the clojure site. (defmulti foo class) (defmethod foo ::collection [c] :a-collection) (defmethod foo String [s] :a-string) (foo []) :a-collection (foo (java.util.HashMap....
Daniel's user avatar
  • 556
2 votes
1 answer
328 views

What exactly happened that we need double dispatch/visitor in c++

I understand the implementation of the solution and the double dispatch/visitor pattern, however I don't understand what happens at compile time and run-time that we need this pattern. For example ...
JayZ's user avatar
  • 254
0 votes
1 answer
111 views

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'...
thburghout's user avatar
1 vote
1 answer
97 views

Overloading method without modifying classes

I have access to a class structure, which I cannot modify, as follows: Graphics Circle Line etc. Again, I cannot modify it! These all have individual properties such as Radius, FirstPoint, ...
Nick Bull's user avatar
  • 9,696
0 votes
1 answer
97 views

Passing shared_ptr<Base> as shared_ptr<Derived>

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::...
Martin Spasov's user avatar
1 vote
0 answers
433 views

C++ Double dispatch with runtime polymorphism?

Is it possible to perform double dispatch with runtime polymorphism? Say I have some classes, and some of those classes can be added/multiplied/etc., and I want to store those dynamically within ...
Adam's user avatar
  • 313
1 vote
1 answer
1k views

C++ double dispatch example

I got this code as an example of use of double dispatch, but I don't really understand one part of the code. creating the "abstract class" Printer, why I need to add: virtual void print(PDFDoc *d)=0; ...
Mr.O's user avatar
  • 342

15 30 50 per page
1
2 3 4 5
7