This project is read-only.
Composite pattern with variable in a class

Design patterns
Description: After define a variable in the class-like structure, use a property to retrieve the result back when comptation is finished. For more information, please go to
type IA<'T> =
abstract member Do : 'T -> unit
abstract member Result : unit -> 'T

let OtherCompositePatternSample3() =
let tree = Tree(1, Tree(11, Node(12), Node(13)), Node(2))
let wrapper =
let result = ref 0
{ new IA with
member this.Do(n) =
result := !result + n
member this.Result() = !result
tree.PreOrder (wrapper.Do)
printfn "result = %d" (wrapper.Result())

Execution Result:
result = 39

Last edited Sep 14, 2011 at 4:22 AM by ttliu2000, version 1


No comments yet.