📜  F#方法覆盖

📅  最后修改于: 2021-01-01 14:34:23             🧑  作者: Mango

F#方法覆盖

方法覆盖是面向对象编程方法的功能。它有助于实现多态性。我们可以使用继承来实现方法重写。让我们来看一个例子。

type Employee() =
 class
  abstract ShowName : unit -> unit
  default this.ShowName() = printfn"This is base class method"
 end

type Manager() =
 class
  inherit Employee()
  override this.ShowName() = printf "This is derived class method"
 end

let employee = new Employee()
let manager = new Manager()
employee.ShowName()
manager.ShowName()

输出:

This is base class method
This is derived class method