One listener for all packets vs separate listeners to handle specific types
-
09-09-2019 - |
Question
Smack's XMPPConnection implements an event-driven manner of receiving XMPP responses from a jabber server. The method addPacketListener (org.jivesoftware.smack.PacketListener, org.jivesoftware.smack.filter.PacketFilter) allows you specify your own custom listener. I'm maintaining code in which one PacketListener handles all types of incoming messages. In the interest of improving the design, (with a nod to the Single Responsibility Principle), I plan to create separate listeners that handle specific types of packets. Is this a good idea ? Another issue is that the messages packet can come from many IM systems e.g. yahoo, google etc... ? Do I create a separate processors for each Yahoo, google services?
Solution
I've decided to use the multiple PacketListeners option. A single PacketListener would be doing too much work, with all the if-else-statements.