This will be in C++11, but the object design should be rather agnostic.
I have 3 interface classes,
The main loop processes multiple kinds of
IEvent, ranging from "an Application has launched" to "User clicked position (x,y)". Then for each type of event, a list of
IConditionare notified through a listener interface. For example,
IEventClickListener::onClick(int x, int y), which is called by the main loop.
If the position is within the conditions, one or more
IRunnable objects are called through
IRunnable::execute(IEvent triggeringEvent), like
class RunnableDrawCircleAtClickPosition and
My problem is as follow :
IRunnable::execute(IEvent triggeringEvent) implementation, I need to get the precise information of the event, but I don't know the exact class hierarchy of the triggeringEvent.
This can be easily solved with dynamic_cast, checking typeid or other reflective oop methods, but those usually breed rather smelly code. I'm also trying to keep the code extendable for new and unrelated events, conditions and runnables that I don't know about yet.
I could also declare a bunch of overloads for
::execute(...) based on children class types, but this doesn't seem right either.
Is there a silver bullet that I've missed here?