For as long as dependency injection gained its popularity (starting with Spring, then followed by Java EE, etc), people have always associated DI with Hollywood Principle – Don’t call us, we’ll call you.
Yet, perhaps it’s just my own ignorance, I have never found any direct translation as to why dependency injection is “Don’t call us, we’ll call you”. Even during some interviews, I have heard quite a number of people being asked, What do you know about Hollywood Principle?. The answer generally follows the line of:
- “It’s dependency injection, period”, or
- “It’s like Spring where by your objects are instantiated with its dependencies, period”.
I have never really found a satisfactory explanation, until today.
Therefore, perhaps more for my own reference, with the hope that those who are as confused as I was previously would find this post beneficial, the best explanation I found is from one of the post by Andrew Binstock (2008). Following is one of the paragraphs I found from the author’s post that I paraphrased.
“Dependency Injection was originally called Inversion of Control (IoC) because as opposed to the normal control sequence where an object finds the objects it depends on by itself, and then calls them, in IoC it is reversed. The dependencies are handed to the object when it’s created. This also illustrates the Hollywood Principle at work: Don’t call around for your dependencies, we (in this case the IoC container/runtime) will give them to you when we need you“(Binstock 2008).
Binstock, A, 2008, Binstock on Software: Excellent Explanation of Dependency Injection (Inversion of Control), accessed 22 March 2012.