I don't understand the Hollywood Principle

Viewed 2395

sorry for my English.

I stumble upon this principle when reading the "Head First Design Patterns" book. I see other peoples ask on StackOverFlow the same question and a few articles but I still don't understand it.

Can someone explain it in the simplest term for me?

Most of the example I've read is assuming that the reader already uses a framework supporting IoC like Spring. I never use those frameworks before because I'm still a beginner.

Thank you.

1 Answers

It's been a while but due to the number of viewers, i explain it.

The Hollywood Principle which sometimes referred to as Inversion of Control says "Don't call us, we'll call you" Which in terms of software engineering it states that an object which depends on another one should not call it but should wait for the other to call it.

This principle defines the IOC with more abstraction. As you know IoC defines inversing the control of dependencies. So first of all you should have a control center responsible for controlling dependencies i.e for making instance of them. This control center then inverses the flow of making instance of classes. So when you want to use ClassA in ClassB, you won't create instance of ClassB then Call ClassA. You make instance of ClassA and pass it to ClassB using different techniques and use it.

For more information about IoC have some invest on the internet as i just explained some basic concepts.

Related