• 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

Inversion of Control

 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I Thought since a lot of the J2EE frameworks that are discussed in this forum utalize IoC I would ask this question here.

What the hell is it? Is there a formal definition? I have googled it but I get stuff that talks about but never really gives a 50 words or less description of it. Tapestry is going with Hivemind on it's next release which uses IoC. Spring uses it, appearntly. And I have no real concept of what it is.

Thanks.
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am downloading Pro Springs Chapter 4 which is on IoC so hopefully that might help clear some things up. But if anyone feels like showing off their knowlegde, I'm all ears.
 
Ranch Hand
Posts: 1209
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not sure about a formal definition. I guess martin fowler was the one who coined the word?

This is what Spring IOC container does and hopefully others also do the same.

A IOC container does object lifecycle management and resolves dependencies between objects it manages.


Actually Spring does lifecycle management (allows you to define the methods that will called during lifecycle) for objects configured as singleton and not for 'prototype' beans.
 
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Karthik Guru:
Not sure about a formal definition. I guess martin fowler was the one who coined the word?

Nope. Martin Fowler just renamed it to "dependency injection"

Originally posted by Karthik Guru:
A IOC container does object lifecycle management and resolves dependencies between objects it manages.


I'll try to summarize IoC in layman's terms...
Your application consists of a number of components, each needing the services of 0..n other components. For each of these components, you enumerate what services they need in a configuration file, and the container (BeanFactory in Spring-talk) will find those required services from the other components and say "Alright, so you wanted an EmailSender, you can use this one over here. I see you also needed a SessionFactory, it just so happens that I've got one for you. Ah, and you also need a DataSource for some odd reason so here's one for you."
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey, are you calling me a layman?

Thanks, that helps. It will probably help for me to use some of this and see it in action also. And to see if it saves me some code/work in my current project.
 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Martin Fowler Article on IoC
 
Ranch Hand
Posts: 365
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How can I programatically retrieve bean's dependencies? For example, say I have a POJO defined with id="Person" in the whatever.xml file. Then I have another bean called "Employee" set to "depend-on" Person is the whatever.xml file.

Now I want to be able to retrieve "Person" and get a list of the beans that "depend-on" it. It looks as though there was a way to do this in the earlier versions but no more.

Any help?
 
Ranch Hand
Posts: 451
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
William,

Spring's IOC is not typically meant to be used to wire up low level business domain objects like the ones you describe. It is more often used to wire up coarse-grained high level application objects (usually singletons) like datasources, transaction managers, proxy and other factories, message sources, validators, ui controllers/mappers, messaging services, security managers and etc. If you are using an ORM like Hibernate, you can use it to wire up your fine-grained domain objects using its versatile association management features.
 
Crusading Chameleon likes the size of this ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic