3 ms·
I wish new programmers weren't shown these "classical" OO design patterns without a corresponding functional pattern. Most of the time the corresponding functio
by alkonaut 9y ago
I wish new programmers weren't shown these "classical" OO design patterns without a corresponding functional pattern. Most of the time the corresponding functional pattern is "pass a function".
Most cases of a factory is basically a Func<Inputs, Output> type function definition. Now that all the big OO languages support it, I'd go for passing creator functions around over defining factories, for nearly all use cases.
This approach works for nearly all the classical GoF patterns.
- harimau777 9y agoAre there any resources that you would suggest for learning about functional patterns?
- austinbirch 9y agoI have found this to be a good read[1]. Examples are in clojure but will apply to other dynamic languages with first-class functions etc. [1]: http://mishadoff.com/blog/clojure-design-patterns/ http://mishadoff.com/blog/clojure-design-patterns/
- alkonaut 9y agoThis page has a few of my favorite resources. Especially the first set of slides there is great. https://fsharpforfunandprofit.com/fppatterns/ https://fsharpforfunandprofit.com/fppatterns/
- humanrebar 9y ago> I'd go for passing creator functions around over defining factories Just call them "factory closures" and everybody wins.