I want to override a virtual method with a derived class type. What\'s the current best way to do this? So far I\'ve found two approaches:
abstract<
You could make the base class generic:
public abstract class Base where TDerived : Base {
public abstract TDerived Clone();
}
public class Derived1 : Base {
public override Derived1 Clone() { ... }
}
public class Derived2 : Base {
public override Derived2 Clone() { ... }
}
However this makes me wonder how useful having a common base class is. Perhaps the Clone implementations of Derived1 and Derived2 don't need to be part of a common interface.