开发者

Efficiently implementing an existing Protocol

开发者 https://www.devze.com 2023-01-30 07:17 出处:网络
I have an existing Protocol I\'d like to write a java Client for. The Protocol consists of messages that have a header containing message type and message length, and then the announced number of byte

I have an existing Protocol I'd like to write a java Client for. The Protocol consists of messages that have a header containing message type and message length, and then the announced number of bytes which is the payload. I'm having some trouble modeling it, since creating a Class for each message type seems a bit excessive to me (that would turn out to be 20+ classes just to represent the messages that go over the wire) I was thinking about alternative models. But I can't come up with one that works.

I don't want anything fancy to work on the messages aside from notifying 开发者_StackOverflow中文版via publish subscribe when a message comes in and in some instances reply back.

Any pointers as to where to look?


A class for each message type is the natural OO way to model this. The fact that there are 20 classes should not put you off. (Depending on the relationship between the messages, you can probably implement common featues in superclasses.)

My advice is to not worry too much about efficiency to start with. Just focus on getting clean APIs that provide the required functionality. Once you've got things working, profile the code and see if the protocol classes are a significant bottleneck. If they are ... then think about how to make the code more efficient.

0

精彩评论

暂无评论...
验证码 换一张
取 消