double-dispatch

Why do I need to Cast Visitor Object to Dynamic for Double Dispatch?

痴心易碎 提交于 2020-05-14 08:54:29
问题 I'd like to know why I need to cast both my visitable object and my visitor to dynamics in order for double dispatch to work without repeated overloads of the Accept method. If I cast either to dynamic but not the other, the generic base class's visit method is called. But if I cast both, then sub-classes' visit methods are called. I have implemented the standard visitor pattern with generics. I have a visitor interface as follows: public interface ITreeVisitorVoid<TPayload> { void Visit

Why do I need to Cast Visitor Object to Dynamic for Double Dispatch?

China☆狼群 提交于 2020-05-14 08:49:10
问题 I'd like to know why I need to cast both my visitable object and my visitor to dynamics in order for double dispatch to work without repeated overloads of the Accept method. If I cast either to dynamic but not the other, the generic base class's visit method is called. But if I cast both, then sub-classes' visit methods are called. I have implemented the standard visitor pattern with generics. I have a visitor interface as follows: public interface ITreeVisitorVoid<TPayload> { void Visit

Double-dispatch and alternatives

时光总嘲笑我的痴心妄想 提交于 2020-02-01 16:12:11
问题 I am trying to find a better way to handle some growing if constructs to handle classes of different types. These classes are, ultimately, wrappers around disparate value types (int, DateTime, etc) with some additional state information. So the primary difference between these classes is the type of data they contain. While they implement generic interfaces, they also need to be kept in homogeneous collections, so they also implement a non-generic interface. The class instances are handled

Double dispatch in Pharo

杀马特。学长 韩版系。学妹 提交于 2020-01-22 19:45:08
问题 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 helpful if some one could explain it with an example. 回答1: Essentially the idea is that you have method: #addInteger: which knows how to add integers, #addFloat: which knows how to add floats, and so on… Now in Integer class you define + as: +

Double dispatch produces 'hides virtual function' warnings, why?

只愿长相守 提交于 2020-01-04 10:59:11
问题 I would like to implement interactions between two objects whose types are derived from a common base class. There is a default interaction and specific things may happen once objects of the same type interact. This is implemented using the following double dispatch scheme: #include <iostream> class A { public: virtual void PostCompose(A* other) { other->PreCompose(this); } virtual void PreCompose(A* other) { std::cout << "Precomposing with an A object" << std::endl; } }; class B : public A {

Storing vector of std::shared_ptr<Foo> where Foo is a templated class

我与影子孤独终老i 提交于 2020-01-02 08:43:28
问题 I have a base class that I made a template because I want to vary the type it takes for several functions, but I want to derive from these templated base classes. I want to store a vector of these classes. My idea was to create a non-templated base class above everything in the hierarchy, and use double dispatching to figure out the type. Am I doing this the "right way"? Here's a code snippet of the scenario: class FooBase { public: virtual void Accept( Visitor &v ); }; template<class T>

How do I use double dispatch to analyze intersection of graphic primitives?

巧了我就是萌 提交于 2019-12-24 03:20:13
问题 I am analyzing the interaction of graphics primitives (rect, line, circle, etc.) and computing the overlap, relative orientation, merging, etc. This is quoted as a prime example of Double Dispatch (e.g. Wikipedia) Adaptive collision algorithms usually require that collisions between different objects be handled in different ways. A typical example is in a game environment where the collision between a spaceship and an asteroid is computed differently than the collision between a spaceship and

Java Class.cast() and Overload

六眼飞鱼酱① 提交于 2019-12-23 18:28:03
问题 I'm trying to code a packet listener for a little server. I'm very new to Java and this is the first time i mess around with networking. The whole idea it's recive the packet, match the packet id with it's class, pass the input stream to the constructor of the packet so it can be constructed and then give it to the packetHander, wich will have an overladed method for each packet. To achive this im using an array that maps the packets ids to the classes of each one, and using a method called

Observer pattern + Visitor pattern for message system

ぃ、小莉子 提交于 2019-12-22 12:17:13
问题 Recently I got into implementing a message dispatching system that uses the "Observer pattern": nothing special here. As I developed it I thought it would be nice to send "Message" objects from the "subject" that could be fundamentally different from each other and could be read from the many "observers". These different messages took the form of different message classes (for example, think about the "User Logout message", "Screen mode toogle" and "Volume level changed", all of these need

What is Single and Double Dispatch?

扶醉桌前 提交于 2019-12-19 05:44:08
问题 i have wrote the visitor pattern as follow but i don't understand what is single and double dispatch. AFAIK, single dispatch is invoke a method based on caller type where double dispatch is invoke a method based on caller type and argument type. I guess double dispatch is happen in single class hierarchy but why visitor class has two class hierarchy but it still considered as double dispatch. void floppyDisk::accept(equipmentVisitor* visitor) { visitor->visitFloppyDisk(this); } void processor