I\'m working on a little Java game in which all sorts of events can happen. There are at least a couple of dozen basic events that various event handlers may be interested in.
If you want to avoid instanceof
, then your only bet is to use inheritance to route a method call to the right method. You cannot use method overloading, since that is decided at compile time by the declared type of the variable you are passing to a method. You have to use inheritance.
If you cannot use inheritance, then your only other choice (that I'm aware of) involves a lot of instanceof
.
Regarding a messaging system, you can use ActiveMQ as an in-the-JVM message transport. You do not have to use it via socket or other means. I can't imagine that ActiveMQ would not be efficient enough for your means.