• 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Liutauras Vilda
Sheriffs:
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
Bartenders:
  • Jesse Duncan
  • Frits Walraven
  • Mikalai Zaikin

Use of depenedency injection

 
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am new to Spring. What I understand from dependency injection is that it is the way by which an object can be created by container. We don't need to use 'new' operator.

I am not getting the benefits of Depenedency Injection. I read that it hepls us in testing our code.

Can somebody please explain me how it helps in testing with the help of an example
 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Spring's dependency injection help programmer to follow OOPS concept. According to the OOPS concept the classes should be loosely coupled if they has dependency. For example class A has dependency on class B, then one has to create object of class B in class A using new operator. In future if someone changes the constructor of class B then it has to make changes in class A also because the constructor has been used in class A to make object of class B. In this scenario we can say that class A is tightly coupled with class B. Using dependency injection feature we does wiring of the bean using configuration file. So we only need to change configuration file instead of the code. I hope this would clarify you doubt.
 
pie. tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic