Tuesday, January 1, 2013


The more I read about IoC, the more it gets complicated. One thing gets clear though, it is one of the the most misunderstood terms. More often than not, it is confused to be an old name for Dependency Injection (DI). Also people tend to understand it directly via some Code Snippet or via its implementation by any Framework.
In reality it’s just a concept borne out of some one’s imagination one fine day. Hence it should be understood irrespective of any code/framework. First came the logic and then came the code.
Most of the people I meet at workplace, have started off their careers by reading a Java or C++ book before they started to code at workplace.
My case have been the other way round. I started off my career without reading any language specific book per say. I googled knowledge out of internet as per the need arose.
I think this would be an apt example of Inversion of Control. Instead of a Book controlling what I learn and in which sequence. I was in the control of what I needed to learn. Googling (Sending Event) about a particular topic as and when required, I learned that topic (Note: The explanation of topics on Google  is eventually the same as in the book).
To be more specific, the e-version of a book v/s printed version. In e-version, I can search the topic I want to read. So the control moves from book (printed version) to the user (e-version)
Thus the Control got INVERTED.
1. GMAT vs CAT
Another good example that I can think of IoC is GMAT exam vs CAT exam. Those who have taken GMAT would understand this better. A question pops up, you have answer it. Then only you can move to the next question. You can’t skip and come back later to the same question. The control is with the Application (GMAT Software).
Consider at the same time CAT Online Exam. We can skip questions, come back later. Choose what question to solve when. Thus some control is shifted to the person who is taking the Exam (Inversion of Control).
2. Simple Delivery vs Midnight Delivery
Another Example is Simple vs Midnight Delivery Service. In simple service, we book a courier. It is upto the delivery guy at what time he will deliver within the SLA.
Midnight Delivery Service is when we want to send our Girl Friend flowers at midnight. Here we are able to set the time when the Delivery guy should deliver (midnight). We can even call the Delivery person and specify/change the timing. Some control shifts from the wish of Delivery Guy to us.
Complete IoC will happen if say someone has sent us a courier. When we get home, we call up the delivery guy and say , “Now I am home, you come and deliver”.

1 comment: