This project is read-only.
Proxy pattern

Category:
Design patterns
Description: Proxy pattern provides a placeholder to expose different methods. For more information, please go to http://en.wikipedia.org/wiki/Proxy_pattern
Code:
type CoreComputation() = 
member this.Add(x) = x + 1
member this.Sub(x) = x - 1
member this.GetProxy(name) =
match name with
| "Add" -> (this.Add, "add")
| "Sub" -> (this.Sub, "sub")
| _ -> failwith "not supported"

let proxy() =
let core = CoreComputation()
let proxy = core.GetProxy("Add")
printfn "result = %d" ((fst proxy) 1)

Execution Result:
result = 2

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

Comments

No comments yet.