此示例(计数器示例)在FSharp的“删除循环依赖项”中给出了乐趣和收益。 https://fsharpforfunandprofit.com/posts/removing-cyclic-dependencies/。
type Customer(name, observer:CustomerObserver) =
let mutable name = name
member this.Name
with get() = name
and set(value) =
name <- value
observer.OnNameChanged(this)
and CustomerObserver() =
member this.OnNameChanged(c:Customer) =
printfn "Customer name changed to '%s' " c.Name
请参阅observer
类中的参数Customer
。它不会在类型中声明为字段或属性。之后怎么样了?
答案 0 :(得分:5)