I have a pretty big listener interface for an Android chat app. I also have an adapter for the listener, with empty methods.
Here it is:
public static interface Listener {
public void connectionStarted(Server server);
public void onConnected(Server server);
public void onDisconnected(Server server, DisconnectType type);
public void onReconnectStarting(Server server, int reconnectAttempt);
public void onReconnectStarted(Server server, int reconnectAttempt);
public void onReconnectEnded(Server server, int numReconnects);
public void onReconnectCanceled(Server server);
public void onRegistered(Server server);
public void onMessage(Server server, Message msg);
public void onQueryMessage(Server server, User user, String hostmask, String msg);
public void joinedChannel(Server server, Channel channel);
public void partedChannel(Server server, Channel channel);
public void onNames(Server server, List<String> batch);
public void onNamesEnd(Server server);
public void onListStart(Server server);
public void onList(Server server, ListEntry entry);
public void onListEnd(Server server);
public void onIsOn(Server server, List<String> nicks);
public void onWho(Server server, WhoData data);
public void onWhoFailed(Server server, String nick);
public void onWhoIs(Server server, WhoisData data);
public void onWhoIsFailed(Server server, String nick);
public void onWhoWas(Server server, WhoWasData data);
public void onWhoWasFailed(Server server, String nick);
public void onCTCPVersion(Server server, String nick, String hostmask, String version);
public void onCTCPPing(Server server, String nick, String hostmask, String ping);
public void onCTCPTime(Server server, String nick, String hostmask, String time);
public void onNotice(Server server, String nick, String hostmask, String message);
public void onNickInUse(Server server, String nick);
public void myNickChanged(Server server, String oldNick, String newNick, boolean onRegistered);
public void onSASLAuthenticationStarted(Server server);
}
For example, if you look at the listener, it has an onMessage()-method, which is called quite a lot (if the user is in many chat channels). And these "no-op" method calls get redirected to lots and lots of completely unrelated listeners.
I'm pretty sure that Oracle's JVM would be smart enough to optimize away all these no-op method calls, but I have no idea if this is the case for the Dalvik VM.
Do you think I should refactor the listener into smaller interfaces (e.g. ConnectionListener, MessageListener, JoinListener and so on), from a performance and maintainability point of view?