< Previous by Date Date Index Next by Date >
  Thread Index  

[reSIProcate] avoid dynamic_cast!


Hi,

         In reciprocate there is so many dynamic_cast. It let code difficult to read also I think it will affect performance. I have a advice to avoid these dynamic_cast, please give comments!

 

Define an abstract class:

Class MessageProcessor

{

         virtual void ProcessMessage(Message &msg)

{

msg.Process(*this);

}

         virtrual void Process(Message &msg) = 0;

         virtual void Process(SipMessage &msg) = 0;

         virtual void Process(KeepAliveMessage &msg) = 0;

         …….

};

 

And in class Message add member function

Class Message

{

         virtual void Process(MessageProcessor &processor) = 0;

};

 

And in every concrete messge add such member function:

 

Class SipMessage

{

         Void Process(MessageProcessor &processor)

{

         processor.Process(*this);

}

};