G
Guest
I've a number of objects (classes) defined in an application which I'm using
to model packets on a network. I have a class hierarchy of Packet (inherited
by) EthernetPacket (inherited by) IPPacket (inherited by) TCPPacket.
I've some control logic which takes in a data stream and determines which
kind of packet to create. Should this logic be within the constructors of the
packet classes - so I create a Packet and within the contructor of the packet
it itself determines if it's an ethernet, ip or tcp packet.
At the root of this is can a base class change itself into a subclass or
does the determination of the class type have to be down outside of the class
structure.
What I'm finding now is that the logic that determines if a packet is a TCP
packet is encapsulated within it's base class (the IP packet) and therefore I
need to firstly create an IP packet - call the method of the IP object to
determine if this is a TCP packet and then create a TCP packet (and delete
the IP packet) - is this the way to do it or should I recast the IP packet as
a TCP packet.
Sorry if this is confusing.
tia
to model packets on a network. I have a class hierarchy of Packet (inherited
by) EthernetPacket (inherited by) IPPacket (inherited by) TCPPacket.
I've some control logic which takes in a data stream and determines which
kind of packet to create. Should this logic be within the constructors of the
packet classes - so I create a Packet and within the contructor of the packet
it itself determines if it's an ethernet, ip or tcp packet.
At the root of this is can a base class change itself into a subclass or
does the determination of the class type have to be down outside of the class
structure.
What I'm finding now is that the logic that determines if a packet is a TCP
packet is encapsulated within it's base class (the IP packet) and therefore I
need to firstly create an IP packet - call the method of the IP object to
determine if this is a TCP packet and then create a TCP packet (and delete
the IP packet) - is this the way to do it or should I recast the IP packet as
a TCP packet.
Sorry if this is confusing.
tia