Having a bit of trouble with a project at the moment. I am implementing a game and I’d like to have it event-driven.
So far I have an EventHandler class which has an overloaded method depending on what type of event is generated(PlayerMove, Contact, Attack, etc)
I will have either the game driver or the class generate the events. My question is how can I efficiently handle the events without tightly coupling the event generating classes to the event handler and making the use of EDA redundant?
I want to design my own simple handler and not use the built-in Java one for this
If you want to have a single
EventHandlerclass with overloaded methods and your event types do not have any subclasses, then this simple code, which uses reflection, should work:However, if you want to have seperate
EventHandlers for different events, the following would be better.