Talk:Dependency injection/Archives/2009/July

Page contents not supported in other languages.
From Wikipedia, the free encyclopedia

Similarities to lambdas, etc

First of all, the example is hilarious, but probably obstructive (the factory class is great). Second, if I grok the concept correctly, doesn't this warrant a link to Higher-order_function? In essence, standard folds and maps could be considered the simplest instances of dependency injection?

eg, a standard map, map f (x:xs) = (f x):(map f xs) (In Haskell syntax, omitting the base case), takes as input a function that provides some sort of service, and runs it, as long as its types matches up (eg it matches the correct interface). Am I wrong?

As far as I can tell, dependency injection is used to prepare an executable object with some external parameter, and leave it ready for later execution. If map and fold were examples of DI, then every higher order function would be; in my opinion they aren't, because the provided function is consumed at once and doesn't give an object prepared for execution.
Currying and closures, OTOH, do consume an external parameter and return a function that can be executed later. So maybe they are better examples of dependency injection in a functional paradigm. Diego (talk) 22:27, 5 November 2008 (UTC)
IMHO, those concepts are quite different because DI was created to solve problems in Object Oriented systems. It is not an abstract concept that is able to embrace something like Higher-order function.Ramiro Pereira de Magalhães (talk) 15:13, 11 July 2009 (UTC)