Everytime I ask anyone what is Spring Framework or what does it do ?, they simply say me, you remember that Hollywood Principle right "Don't Call me, I will Call you", that's exactly what Spring Framework does.
What should I make out of this ?
Everytime I ask anyone what is Spring Framework or what does it do ?, they simply say me, you remember that Hollywood Principle right "Don't Call me, I will Call you", that's exactly what Spring Framework does.
What should I make out of this ?
Callbacks. :P That's what that means for me. Callbacks are functions that wait to be called.
Sometimes callback models are more efficient, especially with anything to do with parsing
if you imagine the hollywood situation, its way more efficient for the "casting agent" to call everyone once they know who they are going to cast (or even not call) rather than having to keep taking calls from every applicant wanting an update.
It means that a class doesn't manually instantiate the components that it depends on -- something (such as Spring's IoC context) gives the class an instance of each component that it needs. This is usually done either via setters for each component, or a constructor that takes all those components.
Basically instead of a class doing manual instantiation by itself:
public class Foo {
private Bar bar;
public void doStuff() {
bar = new BarImplementation();
bar.doMoreStuff();
}
}
IoC injects the dependency Bar into Foo, so that when you get a Foo object from the context, you know it's ready to use.
public class Foo {
private Bar bar;
public void setBar(Bar bar) { this.bar = bar; }
public void doStuff() {
// bar's already been set by the time this is called!
bar.doMoreStuff();
}
}
You didn't manually instantiate Bar, instead your configuration files (such as Spring XML) set it for you. Additionally, Foo is no longer tied to BarImplementation. Using interfaces allows you to insert different implementations, including mocks used for testing.
See http://en.wikipedia.org/wiki/Inversion%5Fof%5FControl
Spring does other things too but IoC/Dependency injection seems to be the most noted feature. It can help to make a system less coupled and more flexible.