0

Let me explain what I mean with an example.

I have the usual subscribe-post event system, where event handlers are methods with an annotation named @EventHandler or something (in my case it's @EventSubscribe, but whatevers), which have one argument whose type is a subclass of class Event

@EventHandler
public void onSomeEvent(SomeEvent event)
{
    //code here
}

Now, in other people's versions of the subscribe-post event system, I see an empty interface Listener or something similar, which as you can imagine is basically this:

public interface Listener {}

Classes extending Listener are expected to contain methods with @EventHandler, because their EventBus (or EventManager as they might call it) can only take Listener for their registry methods.

In my version, I have tried just ditching the Listener idea and let my EventBus take Objects for their registry methods, which does work just as well as far as I've tried.

Now, I understand that having a Listener interface would make it easier to read as classes extending them are instantly identified as containing Event handlers, but I was just wondering if there were any other benefits to them, because so far I can totally live without that kind of interface.

PS: For future reference, is there a special name for an empty interface, or an empty interface that is used in this manner?

octopod
  • 824
  • 2
  • 10
  • 23

0 Answers0