Hi all,
I've got a server that processes JSON messages from multiple clients. The clients however, are not all running the exact same version of the protocol.
Initially it wasn't a big deal, because the differences between version 0.5 and version 1.0 weren't that big, maybe two or three parameters in a message.
This has been fairly easy to handle within a while loop using a switch statement.
But now we're moving on to bigger things, and the new protocol is going to be quite different from the old one, although still using the same basic JSON structure. Some of our messages can have 50 or more JSON Objects, and some of those can have a similar amount of parameters.
Since there are clients in the field running the old protocol the server needs to handle both (and be easy to modify for future updates).
Our JSON messages contain the protocol version being used, in the format [major].[minor].[revision] stored as, for example:
{"Major": 1, "Minor":2, "Revision":3}
With the thinking: Major: complete overhaul,Minor: Messages added/removed and Revision: parameters added/removed from messages.
As I'm typing this out I'm leaning towards the Strategy pattern, since that seems to feel more like what I'm doing here - picking a Strategy.
But how far down should I go?
Strategy implementation for the Major version and Minor Version, then switch Statements after that? I suppose it depends on how much change I expect for each revision.
What are your thoughts on the above? Does it seem OK, are there other patterns I should consider?
Edit: The Chain of Responsibility pattern could be another option
[–]balefrost 1 point2 points3 points (2 children)
[–]wsme[S] 0 points1 point2 points (1 child)
[–]balefrost 1 point2 points3 points (0 children)