What are the benefits of IOC (Dependency Injection)
Benefits of IOC (Dependency Injection) are as follows:
· Minimizes the amount of code in your application.
· With IOC containers you do not create your objects but describe how they should be created. You can also easily add additional services by adding a new constructor or a setter method with little or no extra configuration.
· Make your application more testable by not requiring any singletons(i.e a class with only one object) or JNDI(.i.e java naming directory interface) lookup mechanisms in your unit test cases. IOC containers make unit testing and switching implementations very easy by manually allowing you to inject your own objects into the object under test.
· IOC supports Loose coupling
· IOC containers support lazy loading of services
Lazy loading:
when a Java program is compiled it does not know that whether the pointer of a Parent class is either pointing to a parent object or child object, hence it will not bind the methods with pointers at the time of compiling it will wait for runtime to attach methods with pointers this is also called dynamic method dispatch this 'attaching' happens on every method call during runtime
2nd type of lazy loading is: remote method invocation
3rd type: Anonymous inner class
4th type: use of 'Class' class