f# - call abstract function from a method's own implementation -
i have tried call abstract function method's own implementation.
[<abstractclass>] type callanabstract () = let dosomethingelse () = printfn "done something.." abstract dosomethingabstract: unit -> unit member this.dosomething = printfn "done something.." dosomethingelse () dosomethingabstract ()
which results in error:
error fs0039: value or constructor 'dosomethingabstract' not defined
is calling abstract function method's own implementation illegal or problem lie somewhere else?
if being illegal case, here (see answer) @mark seemann explains composition on inheritance:
[<abstractclass>] type usecomposition (dosomethingelsedefinedlater) = let dosomethingelse () = printfn "done something.." member this.dosomething = printfn "done something.." dosomethingelse () dosomethingelsedefinedlater ()
what alternatives? i'd avoid passing function via constructor , i'd reuse code, having dosomething
have "some implementation" until call abstract function.
you need use this
reference:
this.dosomethingabstract()
Comments
Post a Comment