Lets say I have this class (just as an example):
internal class Packet
{
private readonly UInt32 _length;
private readonly Byte _type;
private readonly UInt32 _requestId;
}
There are many different types of packets each of which inherit from this class and each packet type can have any number of properties of varying types.
Is there a way to implement every type of packet without using inheritance?
I thought about using a property such as List<Tuple<Type,Value>> _typesSpecificValues – I know it won’t compile but I don’t know how else to express what I mean.
I need to avoid creating an inheriting class for each type of packet because there are about 50 types – or am I just being lazy??
It sounds like you should be creating separate classes, yes.
However, I’m not sure whether I’d make them derive from this class. It sounds like this should be in a
Headerclass (or possibly even a struct) and then you could have multiple classes which each contain aHeader.