I have many T arrays to read. Each array T can represent data of type A, B or C. A: List T B: One T C: Exactly three T
When I read the array T, I can get the list T and determine by reading the first T in the list, whether it is type A, B or C. I was thinking of two possible approaches and would like to know their advantages and disadvantages.
1)
enum {A, B, C};
class X {
enum dataType;
List<T> data;
X(T[] input)
{
}
}
2)
abstract class X
{
abstract int length{get;}
}
class A : X
{
List<T> data;
}
class B : X
{
T data;
}
class C : X
{
T data1, data2, data3;
}
class ConcreteX: X
{
List<T> data;
ConcreteX(T[] input)
{
}
}
class XFactory
{
getX(T[] input)
{
ConcreteX conX = new ConcreteX(input);
}
}
source
share