I know this has been discussed before, but I couldn't find a thread that really answered a few questions that have been bouncing around my head for a few days now. I have in my game a global EventManager system. The way this system works is that any class can override the IEventHandler interface, and register itself to listen for events in the EventManager. Each event name is a string for now, but it will probably be a hashed string later. Then, an event handler must override the HandleEvent method of IEventHandler, and any time an event it is registered for is triggered, this callback is hit.
In theory, this seems like a sound system. However, I have noticed a few anti-patterns I have had to use in order to achieve it. The first is that it is a Singleton. Now, I am well aware of the evils of Singletons, and their effect on code when overused, however I am having a tough time finding another way of doing it. The EventManager is used in nearly every class that does anything meaningful, meaning it would need to be injected as a dependency in a ridiculous number of objects. At this point, I'm asking myself this question: I know Singletons are bad because it creates tight coupling between two classes and it hides the fact that this class needs the Event Manager. But if the EventManager is used by nearly every class, then isn't it inherently tightly coupled with the entire application?
Another anti-pattern that I am noticing is the fact that event passing can be tough to follow and debug. I can't just step through the stack trace to see exactly what is happening when an event is fired. You kind of have to "know" which classes are listening to which events. This works fine now because I'm the only one on this project, but once this project starts becoming bigger, and I bring on new devs, it's going to be a nightmare for them to follow the event handlers (and once the codebase gets large it may be tough for me, the original author, to remember all the places that I'm putting event handlers). So my question is, is there any better way?
Sorry, I know this is kind of a long post, but I hope someone out there that knows more than me can help . Thanks.