Inversion of Control (IoC) can be quite confusing when it is first encountered.
Let to say that we make some meeting in some hotel.
Many people, many carafes of water, many plastic cups.
When somebody want to drink, she fill cup, drink and throw cup on the floor.
After hour or something we have a floor covered of plastic cups and water.
Let invert control.
The same meeting in the same place, but instead of plastic cups we have a waiter with one glass cup (Singleton)
and she all of time offers to guests drinking.
When somebody want to drink, she get from waiter glass, drink and return it back to waiter.
Leaving aside the question of the hygienic, last form of drinking process control is much more effective and economic.
And this is exactly what the Spring (another IoC container, for example: Guice) does. Instead of let to application create what it need using new keyword (taking plastic cup), Spring IoC container all of time offer to application the same instance (singleton) of needed object(glass of water).
Think about yourself as organizer of such meeting. You need the way to message to hotel administration that
meeting members will need glass of water but not piece of cake.
Example:-
public class MeetingMember {
private GlassOfWater glassOfWater;
...
public void setGlassOfWater(GlassOfWater glassOfWater){
this.glassOfWater = glassOfWater;
}
//your glassOfWater object initialized and ready to use...
//spring IoC called setGlassOfWater method itself in order to
//offer to meetingMember glassOfWater instance
}
Useful links:-