A technique for polymorphic invocation of methods based on the types of many (or all) arguments. Compare to single-dispatch, used in common OO languages, where methods can only be polymorphic in the first argument -- the runtime resolution of a.doSomething(x, y, z) depends only on the type of a.
Questions tagged [multiple-dispatch]
106 questions
0
votes
1 answer
Is it possible to use multiple dispatch without knowing the type?
Using multiple dispatch to allow for function overloading within OOP, is it possible for me to run the following code:
@dispatch(int)
def __init__(self, radius: int):
However, remove the int, as the attribute being passed in could either be an…

MrDDog
- 7
- 6
0
votes
1 answer
Why am I unable to import multipledispatch from jupyter notebook?
I'm trying to run a jupyter notebook from within a venv environment configured using PyCharm. However, when I try to run the code from the jupyter notebook I'm getting the following error when trying to import a module I know to exist
import…

Jack O'Neill
- 452
- 4
- 11
0
votes
0 answers
Problem using two constructors, and creating its objects
from multipledispatch import dispatch
class Vehicle:
def __init__(self, ownerID, category, power, make, model, year):
self.ownerID = self.personID
self.category = category
# Ask if we need to enforce "N", "G", "D", "H",…

Ahmad
- 1
- 1
0
votes
1 answer
C++ : Possible Concepts-related bug yields "multiple dispatch"
What's going on here? It seems the ability to declare testGeneric with an auto& parameter creates a weird situation where the function can be used to implement multiple dispatch.
Tested on gcc 10.1 or newer with "-fconcepts-ts" flag, also works on…

Talmid
- 15
- 5
0
votes
2 answers
How to use dynamic_cast efficiently?
There is an abstract class Entity, and other classes like Player and Enemy are inherit from it. When game detects a collision between the entities, the following method is called:
void handleCollision(Entity* ent1, Entity* ent2) {
if…

kastrbl4nik
- 87
- 5
0
votes
2 answers
Is pattern matching (Elixir, Haskell, etc) a limited form of predicate dispatch?
I am quite a fan of functional programming, I do know about pattern matching and multiple dispatch, and that's how I found about predicate dispatch and was wondering ever since whenever or not it has something to do with pattern matching.
I did read…

Alexandru Burlacu
- 21
- 5
0
votes
1 answer
Using parameter packs to automate dynamic_cast checks
I'm trying to implement a communication system inside of a GUI. I would like to avoid the visitor pattern for maintainability reasons. Likewise making a dynamic_cast if else statement is not maintainable. The closest I've come is implementing…

dHubley
- 25
- 4
0
votes
1 answer
Will Java 7's MethodHandles provide multiple dispatch?
Will method-handle objects directly provide the ability to invoke methods using multiple-dispatch. If so, is only double-dispatch supported, or will the dispatching mechanism take as many arguments as necessary into account? If multiple dispatch is…

Mackenzie
- 1,897
- 1
- 19
- 25
0
votes
2 answers
Elegantly comparing polymorphic trees in C++
I have a tree of polymorphic objects. I need to traverse the two trees and compare the nodes. If the nodes have different types, they are not equal. Consider this hierarchy:
struct Visitor;
struct Base {
virtual ~Base() = default;
virtual void…

Indiana Kernick
- 5,041
- 2
- 20
- 50
0
votes
1 answer
What is a good way to identify which specific gameObjects are colliding?
This is with respect to a physics engine. Once a collision occurs, it returns me the information that two gameObjects are colliding. All entities, like player, monster, bullet etc are derived (inherit) from GameObject.
What is a good way to identify…

brainydexter
- 19,826
- 28
- 77
- 115
0
votes
1 answer
Polymorphism and Slicing with references
I didn't fully understand object slicing in C++. With the following example code two objects seem to receive the same processing, but polymorphism works for only one of them.
I'm using references and one of the objects doesn't seem to be sliced. I…

Calimero
- 161
- 1
- 8
0
votes
3 answers
Multiple dispatch solution with full maintainability
Can someone think of a good way to implement multiple dispatch with something like the Object::foo overloads below?
class A {
public:
virtual void accept (Visitor&) = 0;
};
class B : public A {
virtual void accept (Visitor&)…

prestokeys
- 4,817
- 3
- 20
- 43
0
votes
2 answers
C#: is System.Type not a real type? or: working around single dispatch
I've been trying to work around C# not having polymorphic dispatch based on the method argument type, and I have encountered that you can't pass types around.
I basically have an abstract class Model that implements two methods:…

Alexey
- 1,354
- 13
- 30
0
votes
0 answers
Triple dispatch design
I have a situation similar to the following:
class EventHandler { ... };
class Event {void Accept(EventHandler&) { ... }};
class SpecialEventHandler : public EventHandler { ... };
class SpecialEvent : public Event {void…

DrYap
- 6,525
- 2
- 31
- 54
0
votes
1 answer
How to relax a requirement in a method
What does it mean to relax a requirement? For example in a simple method which takes in two Integers and adds them together to another Integer, how can one relax a requirement in that method?
package client
import even.Even
import natural.Natural
…

user2900132
- 1
- 1