In a chat application there may be multiple types of incoming messages to be handled. For example, I have messages of these types: text, link, image, and video. Text and link are handled the same way, but image and video require the file to be downloaded from different server. Also each message may need to be deleted. Deleting each message may be different as well, for example text and link messages just need to be deleted from a database but image and video may require the associated file to be deleted. There may be more such operations on messages that are supported on some type of message -- for example retry download in case of image and video.I have thought of using double dispatch with visitor pattern but it does not fit properly. I need something like triple dispatch but I am not sure which design is better.In the future, there may be more types of messages that may require different type of processing. What type of design will ensure adding a message type is least intrusive to infrastructure code? Preferably without adding items to if statements or switch case blocks.
Processing multiple type of messages in multiple ways
design;design patterns;event programming;event sourcing