I have a library which parses various messages, sent in binary form from multiple devices. Devices are still in active development, and their firmware is changed often, which forces me to support different variations of the protocol 开发者_StackOverflowfor all existing versions.
Let's say that a message prior to revision looked like this:
INFO XXXX YYYY CRC
and after firmware version 50, it changed to:
INFO XXXX YYYY ZZZZ CRC
Does it make sense to name my parser classes like this:
class InfoParser : IParser<IInfoMessage>
{ ... }
class InfoParserRev50 : IParser<IInfoMessage>
{ ... }
They are both doing a similar things, and they need to coexist, and these changes happen all the time, but I was wondering if there is a better way of naming them?
I think it's perfectly acceptable to maintain different versions of you classes if you need to support different versions of parsing at the same time. You can combine this with some sort of dispatch logic to tie it all together. In this way you can support multiple versions simultaneously, and avoid issues that may be associating with trying to specialize your parsers as the specifications evolve e.g. fiendishly nested and long if\else statments, for example.
精彩评论