So today I went back to a programming problem I haven't considered for a long time: collision handling. Disregarding the math involved in just detecting a collision between two objects, what's the usual OOP method of handling the behavior of many different combinations of object types that could be colliding? I'm working in c++, so my first instinct was of course to use inheritance of some kind. This leads to an abstract class something like this:
class Collider {
public:
Rectangle bounds;
virtual void onCollide() = 0;
};
Then I can have data structures like Quadtrees that help me efficiently determine which objects to collide, and populate it with pointers to Collider-derived objects. The problem, of course, is that the main requirement of collision handling is that I know what type both objects are. My handy virtual function lets me define behavior based on what this object is, but what about the other one? The best I can accomplish with this model is
virtual void onCollide(Collider& c) = 0;
...Which doesn't tell me much at all.
The inheritance system in c++ doesn't seem to be equipped for this kind of thing; it seems that any solution which takes many types into account starts to defeat the purpose of using inheritance at all. Everything I try seems to end up as a mess of redundant definitions, and the combinatorial explosion will kill me later on if I'm not careful.