lundi 25 mai 2015

What is the functional analogue of a Strategy pattern?

Disclaimer: I do not use functional languages; only trying to comprehend some parts of FP.

Google suggest the articles where first order functions with lambdas can offer the similar functionality which Strategy pattern gives.

Yet we somehow need to match data and corresponding lambda. With OO-design this is done automatically with VMT, that is the type itself carries the important information needed to reason about execution flow making further addition of a new behavior easy (open closed principle): inherit and override. Old code simply stays unchanged. Functional pattern matching seems to be static in this regard and does not allow such kind of dynamics.

Sure, it is possible to code a configurable matching behavior for selecting lambda based on given data, but it isn't it what we have in OOP out of the box?

Aucun commentaire:

Enregistrer un commentaire