This project is read-only.
Factory pattern

Category:
Design patterns
Description: Factory pattern implementation: it returns different types based on inputs. For more information, please go to http://en.wikipedia.org/wiki/Factory_method_pattern
Code:
let factorySample() = 
let factory = function
| TypeA -> { new IA with
member this.Action() = printfn "type A" }
| TypeB -> { new IA with
member this.Action() = printfn "type B" }
let output = factory Type.TypeA
output.Action()

Execution Result:
type A

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

Comments

No comments yet.