• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Inversion of Control:question

 
Ranch Hand
Posts: 136
Eclipse IDE Chrome Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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)?
 
best scout
Posts: 1294
Scala IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic