个性化阅读
专注于IT技术分析

F#抽象类

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

句法:

// Abstract class syntax.
[<AbstractClass>]
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#抽象类示例

[<AbstractClass>]
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.
赞(0)
未经允许不得转载:srcmini » F#抽象类

评论 抢沙发

评论前必须登录!