Another way to ask this question is: what is Inversion of Control according to you?
I ask this question because the Wikipedia article on IoC has been hijacked by a non-OO explanation. This is taken from the discussion page and is from 2007:
I took the liberty to completely rewrite the page, as the previous content was completely taken over by meaningless “object oriented” babble …
I don’t see how Inversion of Control makes any sense outside of OO language. There are already many explanations for giving up control in procedural languages (event programming is one) and purely functional languages don’t need a concept like Inversion of Control since they have higher-order functions.
Also, in the article where Martin Fowler elaborates on IoC he exclusively handles OO examples.
So, is IoC exclusively an OO concept, and what is it exactly?
To me, IoC tries to turn functions into data within the limitations that most OO languages impose, and tries to pass those functions-as-data as arguments to other functions. That’s not the only part of IoC, but there’s some of that.
There’s also the factory design pattern, where trees of objects are being constructed and configured before being passed on.
To me, IoC is exclusively an OO concept.
What’s your answer?
You look at the theoretical problem from a implementational viewpoint. The first question that arises should be exactly what Control do you Invert ?
Then you will realize that it doesn’t matter wether its an object, method, function or whatnot that is passed around, but what actually the code does.
In short, when you do Dependency Injection, you invert the control of the creation and usage of dependencies (of resources).
When you give a Windows API function a pointer to a callback function, you give them the control of calling your function with their own parameters.
So you see, IoC is just a theoretical concept, and ofcourse, there can be different practical implementations of it.