double-dispatch

Double dispatch/multimethods in C++

廉价感情. 提交于 2019-11-27 14:28:21
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 BaseClass type. What is the most efficient (performance-wise) way to accomplish this? After googling around for a while I found out about double dispatch and the loki multimethods. The problem I have with the Shape examples is that in my application, Processor and BaseClass are entirely independent and don't have a common method that they can call in

Understanding double dispatch C++

≡放荡痞女 提交于 2019-11-27 07:20:17
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 class is defined what happens if warrior fights with warrior or with monster etc. I wrote the following code: #include<iostream> using namespace std; class Monster; class Warrior; class Creature{ public: virtual void fight(Creature&) =0; }; class Monster: public Creature{ void fightwho(Warrior& w) {cout<<"Monster versus Warrior"<<endl; } void

Java method overloading + double dispatch

我只是一个虾纸丫 提交于 2019-11-26 23:10:38
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 here? Any direct reference to Java Lang Spec? Which term describes this behaviour? Thanks a lot. public class InheritancePlay { public static class Parent { public void doJob(Worker worker) { System.out.println("this is " + this.getClass().getName()); worker.print(this); } } public static class Child extends Parent { } public static class Worker { public

Understanding double dispatch C++

一世执手 提交于 2019-11-26 17:38:21
问题 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 class is defined what happens if warrior fights with warrior or with monster etc. I wrote the following code: #include<iostream> using namespace std; class Monster; class Warrior; class Creature{ public: virtual void fight(Creature&) =0; }; class

Double dispatch in C#?

ⅰ亾dé卋堺 提交于 2019-11-26 15:51:59
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? The visitor pattern is a way of doing double-dispatch in an object-oriented way. It's useful for when you want to choose which method to use for a given argument based on its type at runtime rather than compile time. Double dispatch is a special case of multiple dispatch . When you call a virtual method on an object, that's considered single-dispatch because which actual method is called depends on the type of the single object.

Java method overloading + double dispatch

只愿长相守 提交于 2019-11-26 12:19:45
问题 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 here? Any direct reference to Java Lang Spec? Which term describes this behaviour? Thanks a lot. public class InheritancePlay { public static class Parent { public void doJob(Worker worker) { System.out.println(\"this is \" + this.getClass().getName());

Difference betwen Visitor pattern & Double Dispatch

妖精的绣舞 提交于 2019-11-26 10:30:41
问题 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 回答1: In short they come from to different conceptualizations that, in some languages where double dispatch is not natively supported, lead to the visitor pattern as a way to concatenate two (or more) single dispatch in order to have a multi-dispatch surrogate. In long The idea of

Double dispatch in C#?

老子叫甜甜 提交于 2019-11-26 05:57:42
问题 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? 回答1: The visitor pattern is a way of doing double-dispatch in an object-oriented way. It's useful for when you want to choose which method to use for a given argument based on its type at runtime rather than compile time. Double dispatch is a special case of multiple dispatch . When you call a virtual method on an object, that's