jeudi 30 janvier 2020

Design help- Design pattern for handling a generic interface for different types of messages

I have to bring up an interface for a node which can receive messages with same header but different message types. The message type comes at a fixed position in the header always. These message types can further be divided into two classifications - Atype(a set of 6 messages) and Btype(a set of 8 messages). The design needs to provide support to add a new message type (eg Ctype) to the interface easily. I have been thinking of writing an interface class which has a std::map with message_type being Atype or Btype and the message_handler_type is a function call to the corresponding message handlers(based on two singleton classes for AtypeMessage and BtypeMessage) - AtypeMessage::get_instance()->AtypeMessageHandler() or BtypeMessage::get_instance()->BtypeMessageHandler() and pass the message along to the corresponding message handler based on the message_type. This node will receive huge amount of traffic. Will this be a good enough design for future extension? Is there any other good design options that I am missing out?

Aucun commentaire:

Enregistrer un commentaire