I'm defining two Abstract Classes: AC1, and AC2. AC1 has a property (variable) which is a List of type AC2 (List<AC2>) (that's my way of defining a 1 to many relation).
Then, I defined R1 which comes from AC1 (R1 : AC1) and R2 : AC2. The problem comes when I'm writing R1's constructor. I'm passing as a parameter a List of type R2 (List<R2>) and then try to assign it to the property (variable) defined in AC1 (List<AC2>), but this fails as it cannot implicitly convert from R2 to AC2 (even when R2 comes from AC2).
Code example:
abstract class AC2
{
//several properties and methods here
}
abstract class AC1
{
List<AC2> dammVariable {get; set;} //problematic variable (see class R1)
//other stuff here
}
class R2 : AC2
{
//some properties exclusive for R2 here
public R2(){}
}
class R1 : AC1
{
//some properties exclusive for R1 here
public R1(List<R2> r2s)
{
this.dammVariable = r2s; //I found the error right here
}
}
I'll have some other classes coming from this abstract classes, but each time that I create a class (X2, for example) that comes from AC2 I'll need an X1 class that has a List<X2>.
Am I failing in design or implementation?
I'll appreciate any help.