I am making a network application. Here is the problem:
I have a Messenger class. The Messenger has several module classes named ModuleA,B,C etc. The messenger sends MessagePacks (to other Messengers). Each MessagePack has a module destination meaning once it reaches Messenger it is forwarded to the correct Module(A,B,C etc).
At the moment in order to forward to the correct module I'm using an if-else checking for a tag on MessagePack to decide where to forward.
What I would like to do is have MessagePack subclasses instead of using tags(tags are Strings).So TypeAMessage goes to ModuleA etc. The only way I can think to do that is having an instance of Messenger in the MessagePack and call a method like this: Messenger.fowardToModuleA(this); but it doesn't make sense(and probably causes problems) to have an instance of Messenger on MessagePack.
Can anyone think of a way to complete the task I want without using the if-else checking for tag strings and preferably using MessagePack subclasses?