File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Spring and the fly likes Inversion of Control:question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Inversion of Control:question" Watch "Inversion of Control:question" New topic
Author

Inversion of Control:question

Arun Kumar
Ranch Hand

Joined: Jan 21, 2005
Posts: 129

I am learning Spring now. so please forgive my ignorance

What is the advantage of using IOC to call another class rather than using the new operator? isit it just a over head that we need to main tain one more configuration file?

what makes spring this much apealing than a normal J2EE application(I maean teh old way in which used new for creating objects)?
Marco Ehrentreich
best scout
Bartender

Joined: Mar 07, 2007
Posts: 1282

Hi Arun,

isit it just a over head that we need to main tain one more configuration file?


Do you really think IoC would be that popular today if it would only be useful to produce some overhead? Seriously, of course the advantages are not to have an additional configuration file In general IoC principles (not only in Spring) help to create application architectures which are loosely coupled. From a design perspective such applications are relatively easy to maintain, extend, test and other things.

With loose coupling it's easy to exchange any software component with another one without having to modify the whole application. This also helps to maintain or extend components without breaking the whole application. For testing purposes it's easy to swap in some test double like a mock or stub instead of the real component.

In contrast with the new operator used directly inside of a specific class it's impossible to change the class you are instantiating without having to modify the code of the class which needs the other class. With an external configuration like the Spring framework offers it's easy to wire different classes and objects together without the need to re-compile anything! You can just configure which components are needed for which other components and the IoC container takes care to instantiate and wire all objects together as needed.

There is more to IoC like lifecycle management of objects and components for example. But I hope it's a little bit clearer that IoC definitely gives you some advantages! Of course it's still no guarantee to create excellent applications just because you use an IoC framework. But it helps you a lot if you are willing to create applications with a reasonable architecture and design. I guess you should find a lot of detailed information on the internet about IoC in general and the Spring framework in particular.

what makes spring this much apealing than a normal J2EE application(I maean teh old way in which used new for creating objects)?


In my opinion with JEE 5 and in particular JEE 6 the Java EE platform has become a lot more interesting in contrast to Spring than it was before JEE 5. Spring has become very complex and feature rich (with all the different modules and sub projects) but it still tries to sell itself as a lot more lightweight alternative to JEE. OK, J2EE <= 1.4 was really heavyweight and cumbersome to use but that has changed. So for me a lot of the so called advantages of Spring are no longer real advantages. But anyone who likes Spring will probably tell you that I'm wrong

That said JEE offers IoC capabilities, too. Particularly the new release 6 with it's CDI and injection framework has vastly improved the dependency injection and IoC capabilities of the JEE platform

Marco
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Inversion of Control:question