I got an abstract super class called MyBase. I'm going to store away a collection of subclasses (MySubClass1, MySubClass2, etc.) in to a List(Types::Class) variable, which will be serialized as part of an outer data structure. So I would need to implement a static MyBase::create(container) method which will be internally called by List::unpack() and, let alone unpacking, must instantiate an appropriate type of a subclass based on super classType member. I hope you get the idea.
Suppose I have an abstract super class:
abstract class MyBase implements SysPackable
{
MyEnum classType;
#define.baseVersion(1)
#localmacro.baseList
baseVer, classType
#endmacro
}
I also have subclasses, every which one looking akin:
class MySubClass1 extends MyBase
{
int subValue1;
str subValue2;
#define.subVersion(1)
#localMacro.subList
#baseList, subVer, subValue1, subValue2
#endmacro
}
How would you go about implementing pack/unpack/create serialization pattern for such hierarchy? Maybe there is a better way to accomplish what I need?