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);

The base message class is required for the classic OO response An abstract method that converts solid message subclasses to deliver a specific message.

Something (not too broad) Teachers like Dillon and Klaspep are "very popular" (are dynamically transmitted on logic types).

A flexible approach to popular languages ​​is Uncle Bob's "escalar visitor" design pattern; For visitor type, www.ccs.neu.edu/research/demeter/adaptive-patterns/visitor-use/documents/plop96/ variations-visitor-nordberg.ps.


Comments