0 people like it.

Pimpl ctor ref prop

Sim

 1: 
 2: 
 3: 
 4: 
 5: 
 6: 
 7: 
 8: 
 9: 
10: 
11: 
12: 
13: 
14: 
15: 
16: 
17: 
18: 
19: 
20: 
21: 
22: 
23: 
24: 
25: 
26: 
27: 
28: 
29: 
30: 
31: 
32: 
33: 
34: 
35: 
36: 
37: 
38: 
39: 
[<AbstractClass>]
type GameScreen(?prop : ref<string>) =
    member val Prop = !(defaultArg prop (ref "GameScreen.Prop"))
    abstract Update : unit -> string

let loadingScreen () =
    { new GameScreen(prop = ref "LoadingScreen.Prop") with
        override o.Update() = "loadingScreen.Update"  }

[<AbstractClass>]
type MenuScreen(?prop : ref<string>) =
    inherit GameScreen(prop = defaultArg prop (ref "MenuScreen.Prop"))
    abstract OnCancel : unit -> string
    default o.OnCancel() = "MenuScreen.OnCancel"

let pauseMenuScreen () =
    { new MenuScreen(prop = ref "PauseMenuScreen.Prop") with
        //override o.OnCancel() = "pauseMenuScreen.OnCancel"
        override o.Update() = "PauseMenuScreen.Update" }

module Example =
    let gameScreens : GameScreen[] = [| loadingScreen () ; pauseMenuScreen () |]

    let testGameScreens (screens : GameScreen[]) =
        for gs in screens do
            gs.Prop |> printfn "%s"       
            gs.Update() |> printfn "%s"

    testGameScreens gameScreens

    let menuScreens : MenuScreen[] = [| pauseMenuScreen () |]

    let testMenuScreens (screens : MenuScreen[]) =
        for ms in screens do
            ms.Prop |> printfn "%s"       
            ms.Update() |> printfn "%s"
            ms.OnCancel() |> printfn "%s"

    testMenuScreens menuScreens
Multiple items
type AbstractClassAttribute =
  inherit Attribute
  new : unit -> AbstractClassAttribute

Full name: Microsoft.FSharp.Core.AbstractClassAttribute

--------------------
new : unit -> AbstractClassAttribute
Multiple items
type GameScreen =
  new : ?prop:string ref -> GameScreen
  abstract member Update : unit -> string
  member Prop : string

Full name: Script.GameScreen

--------------------
new : ?prop:string ref -> GameScreen
val prop : string ref option
Multiple items
val ref : value:'T -> 'T ref

Full name: Microsoft.FSharp.Core.Operators.ref

--------------------
type 'T ref = Ref<'T>

Full name: Microsoft.FSharp.Core.ref<_>
Multiple items
val string : value:'T -> string

Full name: Microsoft.FSharp.Core.Operators.string

--------------------
type string = System.String

Full name: Microsoft.FSharp.Core.string
val defaultArg : arg:'T option -> defaultValue:'T -> 'T

Full name: Microsoft.FSharp.Core.Operators.defaultArg
abstract member GameScreen.Update : unit -> string

Full name: Script.GameScreen.Update
type unit = Unit

Full name: Microsoft.FSharp.Core.unit
val loadingScreen : unit -> GameScreen

Full name: Script.loadingScreen
val o : GameScreen
abstract member GameScreen.Update : unit -> string
Multiple items
type MenuScreen =
  inherit GameScreen
  new : ?prop:string ref -> MenuScreen
  abstract member OnCancel : unit -> string
  override OnCancel : unit -> string

Full name: Script.MenuScreen

--------------------
new : ?prop:string ref -> MenuScreen
abstract member MenuScreen.OnCancel : unit -> string

Full name: Script.MenuScreen.OnCancel
val o : MenuScreen
override MenuScreen.OnCancel : unit -> string

Full name: Script.MenuScreen.OnCancel
val pauseMenuScreen : unit -> MenuScreen

Full name: Script.pauseMenuScreen
module Example

from Script
val gameScreens : GameScreen []

Full name: Script.Example.gameScreens
val testGameScreens : screens:GameScreen [] -> unit

Full name: Script.Example.testGameScreens
val screens : GameScreen []
val gs : GameScreen
property GameScreen.Prop: string
val printfn : format:Printf.TextWriterFormat<'T> -> 'T

Full name: Microsoft.FSharp.Core.ExtraTopLevelOperators.printfn
val menuScreens : MenuScreen []

Full name: Script.Example.menuScreens
val testMenuScreens : screens:MenuScreen [] -> unit

Full name: Script.Example.testMenuScreens
val screens : MenuScreen []
val ms : MenuScreen
override MenuScreen.OnCancel : unit -> string
Raw view Test code New version

More information

Link:http://fssnip.net/aU
Posted:14 years ago
Author:
Tags: