Ashwini Taradale
Ashwini Taradale

Reputation: 39

How to handle slight deviation from Liskov substitution principle

I landed in a situation where I need to derive from an existing class that represents a tcp packet, lets call it PacketA. It contains length of the packet name and name itself in it's header so there are methods in PacketA class that helps to retrieve name and name length. Now I need to create another class let's call it PacketB which has identical properties as PacketA except it has no name and name length field. So I am thinking to derive PacketB from PacketA and override methods that have different behavior. Also plan is to throw an exception from methods that PacketB don't support, mainly name and name length.

This clearly don't follow Liskov substitution principle. Is there any way to implement this in cleaner way?

Upvotes: 0

Views: 38

Answers (0)

Related Questions