I have an abstract class ClassA, with an abstract method that takes a paramter of type ClassB. Several classes derive from it. Now I add another project, which has similar functionality, but needs a slightly different base ClassA, to derive its several classes from. The main difference: The new base class, ClassC, shouldn't ClassB as argument, but another one, that's derived from B, ClassD. ClassC should then be used as base by several classes again.
Is this possible? This is more of a question out of curiousity. I know it is possible with generics, by doing this:
public abstract void Method1<T>(T parameter) where T : ClassB;
...
public override void Method1<ClassB>(ClassB parameter) {
Is it possible without generics? And is there any dowside to them, aside from having to type the type twice?
abstract class ClassA
{
public abstract void Method1(ClassB parameter);
}
class DerivingClasses1 : ClassA
{
public override void Method1(ClassB parameter)
{
// do something
}
}
// -------
abstract class ClassC : ClassA
{
// This would have to override Method1 of ClassA somehow,
// instead of overloading it.
public abstract void Method1(ClassD parameter);
}
class DerivingClasses2 : ClassA
{
public override void Method1(ClassD parameter)
{
// do something
}
}
// -------
class ClassB
{
}
class ClassD : ClassB
{
}