This week's book giveaway is in the Reactive Progamming forum.
We're giving away four copies of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams and have Adam Davis on-line!
See this thread for details.
Win a copy of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams this week in the Reactive Progamming forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

How is IoC useful over conventional object instantiation ?

 
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I'm relatively new to Spring and espicially to IoC. Unrelated to Spring, can some one explain me with an example, how IoC is useful over conventional object instantiation (using new keyword). What is the benefit of this re-direction, where in creation and wiring of the objects is delegated to IoC container instead of handling it in code. I'm pretty sure that, there might be something apart from freeing the code from object creation, which does not seem to be lot of problematic.
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
IoC allows us to decouple the interface from the implementation, and can allow external forces to determine the implementation.

Consider the implications for testing method foo:We can only test foo() with an instance of a Bar. If we need to test the return value of foo(), we now have to re-implement our Bar.baz() to return each of the possible conditions foo() could encounter. If, on the other hand, we allow the Bar to be set, our unit test can decide which condition we're testing:IoC also allows for strong configurability. Consider a program intended to allow easy extension or modification of key components. Instead of going in and changing the original source code, we can just tell the program at startup which implementation to use. This might allow us to customize how HTTP requests are handled, provide a plugin mechanism, and so on.
 
Schandha Ravi
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for explaining with an example. I have started reading "Spring in action" to understand more on this framework and I'm sure that I would come up with more questions to ask.
 
I am going to test your electrical conductivity with this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!