Refactoring towards Visitor Pattern

Dear all

This was on my mind for a long time ( removing  packet.payloadDescriptor() and switch/case statement … )

OO recommends removing this … So what is the solution?

This is where the Visitor pattern ( GOF ) fits very nicely…

So I put in the Visitor framework and made

PacketProcessor::packetReceived

a visitor….

Here is the patch…

Let me know what you all think…

( One nice fallout is if we add any new packet the compiler will help us make sure all the relevant code gets updated ;-)

— cheers atul

Attached Files:

Would you like to post a relpy?


This post starts a thread.
Follow-ups:
Re: Refactoring towards Visitor Pattern
Hi Atul, I love the idea! Never thought of that! You’re quite right that using a visitor will get us rid of the switch statements and the compiler would be able (more...)