design patterns - How to handle different processing based on message type? -
I have a procedure in which "notification" method that receives as a parameter, the type of message type class . Based on the message of derivative type I want to do various processing. Does it mean that I need to add something similar to a method called "Process" or message type, and implement it using polymorphism? Is it better to add "notification" to each specific message type?
More information: Language is C ++ I thought that would be a good idea here, so I would only need one method to be informed about different message types. The controller inherits from a listener who indicates a pure vitamin (MsgBaseClass) method. I still like that idea because I do not have to inform every new message type. But in the controller code, I do not see any way to differentiate between some message messages like dynamic dense or to add a message type in the message.
EDIT: I think that I'm going with the Visitor Pattern, it allows me to keep only one way to notify me, and I can avoid a switch statement in my code . A "visitor" interface will specify the various methods required by the listener to process different derivative message types. For this, only one message can be added to the message base class, a pure virtual "accept (mimase type weaver v). The derived message class will apply it using v.visit (it);
Comments
Post a Comment