• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

When we can use Spring IOC?

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

In which situations we use spring IOC. Please give me example. If any change is happened in the Bean xml we are changing the code also where the loose coupling is happening in Spring IOC.
 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am giving one example and briefly how loose coupling works in Spring
If you use object's dependencies as interfaces and not as "concrete" objects

Interface : PaymentInterface
Implementation : PaymentInterfaceImpl
method : validate()
Let assume that it will do Credit card validation
Your code will have a setter method for “PaymentInterface” in your java code
And xml or applicationContext.xml file you will have
<bean id=" paymentInterface" class="com.old.PaymentInterfaceImpl"/>
So your object is created by Container and injected through setter method and no where in your code you are creating an object

Now some other Service which will do the same validation and now you want to use that service
Your actual Interface : PaymentInterface
New Implementation : NewPaymentInterfaceImpl
Your method is : validate()
Now your service Impl has changed .
Your new service will implement validate method of PaymentInterface
Now in xml you change your code as
<bean id=" paymentInterface " class="com.new.NewPaymentInterfaceImpl "/>
You no need to change any code for object creation etc in your java file




 
vijay kumar sharma
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Murali,

Thanks for your reply. I got the point.
 
reply
    Bookmark Topic Watch Topic
  • New Topic