I'm writing an application that sends and receives messages over the network and pushes them into a
std::deque queue. and I'm looking for the appropriate programming pattern to handle all of the different possible types of messages that it could receive.
Each type message will have a completely different set of data. For example:
Another peer connected
- Peer name
- Peer address
- Other peer state
Sync object state
- location delta
- rotation delta
- other object state
Meta Event A
- Some data
Meta Event B
- Some data
My initial reaction is to create a base class
Message and then create subclasses
PeerConnectedMessage, etc. because each message requires completely different member variables than the other events.
I get stuck when I go to process my message queue. Everything I've read says to avoid using a switch and to determining which class a message belongs to (see here).
Is there a better way to approach this problem? I don't think that I want the messages themselves to act upon the state of the rest of my application, but rather act as data bags, and let me manage my application state in the class that works through the queue.