Skip to main content

Posts

Showing posts with the label IOC & DI

Dependency Injection (DI) vs. Inversion of Control (IOC)

The main goal of Inversion of control and Dependency Injection is to remove dependencies of an application. This makes the system more decoupled and maintainable. First let’s try to understand IOC (Inversion of control). If you go back to old computer programming days, program flow used to run in its own control. For instance let’s consider a simple chat application flow as shown in the below flow diagram. End user sends chat message. Application waits for the message from the other end. If no message is found it goes to Step 2 or else moves to Step 4. Displays the message. User continues with his work ahead. Now if you analyze the program flow closely, it’s sequential. The program is in control of himself. Inversion of control means the program delegates control to someone else who will drive the flow. For instance if we make the chat application event based then the flow of the program will go something as below:- End user sends chat message. User continues with his...