I have a process which has a "notify" method which receives as a parameter the base class of the message type. I'd like to do different processing based on the derived type of message. Does this mean I need to add a method called "process" or something similar to the message type, and invoke it using polymorphism? Is it better to add a "notify" for each specific message type?
More details: The language is C++. I thought notify would be a good idea here, so that I would only need one method to be notified of the various message types. The controller inherits from a listener class which specifies a pure vitual notify(MsgBaseClass) method. I still like that idea, since I don't have to add a notify for each new message type. But in the controller code itself, I don't see any way to distinguish between the message type other than something like dynamic cast, or adding a message type to the message.
edit: I think I'm going to go with the Visitor pattern. It allows me to keep just one method for the notify, and I can avoid a switch statement in my code. A "visitor" interface will specify the various methods needed by the listener to process the various derived message types. This will require only one message to be added to the Message base class, a pure virtual "accept(MyMessageTypeVisitor v). The derived message classes will implement it using v.visit(this);
I think this oughta work.