📜  F#抽象类

📅  最后修改于: 2021-01-01 14:35:16             🧑  作者: Mango

F#抽象类

抽象类是那些不提供类成员的完整实现的类。它可能包含非抽象方法。继承抽象类的类必须提供抽象类的所有抽象方法的实现。抽象类用于实现抽象。

句法:

// Abstract class syntax.
[]
type [ accessibility-modifier ] abstract-class-name =
[ inherit base-class-or-interface-name ]
[ abstract-member-declarations-and-member-definitions ]

// Abstract member syntax.
abstract member member-name : type-signature

F#抽象类示例

[]
type AbstractClass() = 
 class
  abstract member ShowClassName : unit -> unit
 end

type DerivedClass()  = 
 class
  inherit AbstractClass()
  override this.ShowClassName() = printf "This is derived class."
 end

let a = new DerivedClass()
a.ShowClassName()

输出:

This is derived class.