Re: Packet class \todo - ‘developers/peter/calitko-dev,225′

Hi Peter,

We currently have situations in Gnutella’s PacketProcessor and similar classes where the packets are modified. For example, before forwarding a Gnutella packet its hops has to be increased and its ttl decreased. One option will be that we modify the object itself, another would be that the setters return a new object (as suggested in one of the linked articles). I’m not certain which one is better… For class Torrent you made a perfect point why its objects should be immutable but we would need to manipulate packets as part of our packet processing…

Ah, I see… I was looking to the Gnutella Packet declarations and if the only operations with a packet would be something like doHop();, then I’d stick to modify the original packet (because there is nothing to corrupt). But if we need operations like setDescriptorId(), setTtl() and setHops(), then we maybe we should create a modified copy of the packet. But there is also the isValid() function so maybe we can modify packets anyway and only check their validity before some other processing whether they’re correct or not (the difference is that the Torrent class doesn’t have the isValid() function). I don’t know what other packet operations do we need.

So from what I’ve read I’d stick to the value object variant (modify the object itself), in spite of they won’t be immutable…

Petr

Would you like to post a relpy?


This post is a reply to:
Re: Packet class \todo - ‘developers/peter/calitko-dev,225′
Hi Petr, thanks for the links! Now I see that there was a misunderstanding from my side over my “understanding” of reference objects. So, I’ve read some of the posts in (more...)

No follow-ups yet.