Inheritance F#静态覆盖

Inheritance F#静态覆盖,inheritance,static,f#,overriding,Inheritance,Static,F#,Overriding,我有一个抽象类,有一个抽象成员。 我想将此成员继承到不同的类中,并使该成员的重写为静态 大概是这样的: [<AbstractClass>] type Parent() = class abstract member Att : int end;; type Son() = class inherit Parent() static override Att = 10 end;; type Daughter() = class inherit Parent() st

我有一个抽象类,有一个抽象成员。 我想将此成员继承到不同的类中,并使该成员的重写为静态

大概是这样的:

[<AbstractClass>]
type Parent() = class
  abstract member Att : int
end;;
type Son() = class
  inherit Parent()
  static override Att = 10
end;;
type Daughter() = class
  inherit Parent()
  static override Att = 20
end;;
[]
类型Parent()=类
抽象成员Att:int
完;;;
类型Son()=类
继承父项()
静态超越Att=10
完;;;
类型子()=类
继承父项()
静态超驰附件=20
完;;;
或者

[<AbstractClass>]
type Parent() = class
  static abstract member Att : int
end;;
[]
类型Parent()=类
静态抽象成员Att:int
完;;;

[]
类型Parent()=类
抽象静态成员Att:int
完;;;
那么所有的儿子都会有Att=10,所有的女儿都会有Att=20。 这是行不通的


有什么方法可以实现这一点吗?

从对象模型的定义来看,这是不可能的——静态方法不能在C#和任何其他对象语言中被重写

例如,这里也提到了这一点(对于Java,但这是面向对象编程的一般性要求):

重写依赖于类的实例。多态性是指您可以对一个类进行子类化,而实现这些子类的对象对于在超类中定义(并在子类中重写)的那些方法将具有不同的行为。静态方法不属于类的实例,因此该概念不适用


特别是对于抽象类,这是没有意义的-您可以在派生类(这意味着它不需要在超类中定义)或超类(这意味着它不需要是抽象的)或实例(这意味着它不能是静态的)上调用该方法。

解决方案是否要求您使用静态的?或者,解决方案是否要求,一旦创建了子Att=10,并且创建了子Att=20,则不能更改它们?e、 readonly实际上解决了这个问题。非常感谢,我不知道。非常感谢你。
[<AbstractClass>]
type Parent() = class
  abstract static member Att : int
end;;