我想知道具体(即非抽象)类的子类是否可以是抽象的。在一个虚构的例子中:
public class HistoricallyManaged<SpecificType>
{ // code to manage history }
public abstract class ComputationalNode<SpecificType>: HistoricallyManaged<SpecificType>
{ // common methods implemented, but some left to concrete classes }
public class Formula<SpecificType>: ComputationalNode<SpecificType>
{ // code to manage common formula behavior like checking if parameters have been calculated }
public class Variable<SpecificType>: ComputationalNode<SpecificType>
{ // code to manage common variable behavior like persisting values }
// usage example
public class SomeOtherClass {
private Formula<int> intFormula;
private Formula<double> doubleFormula;
private Variable<int> intVar;
private Variable<double> doubleVar;
}
在上面的示例中,我想禁止实例化ComputationalNode或使用模板绑定来创建类似ComputationalNode的类型,但是我确实希望允许声明HistoricallyManaged和其他类型,因此必须可以在层次结构中进行更高的实例化,但不能在中间级别。
感谢您的宝贵帮助。