See below programs for clear differentiation with and without IOC.
public class Student {
private Address address;
public Student() {
address = new PuneAddressImpl();
}
}
In above code we need to mention implementation class (new PuneAddressImpl ()) there itself. We can see implementation is mentioned in Student class itself.
Now same code we will write through IOC by using dependency injection.
public class Student {
private Address address;
public void setAddress(Address address) {
this.adddress=address;
}
}
In above code we can send implementation class from other class it may be a testing class or a any layer of our application. This is called as dependency injection.
In spring all objects are referred as a beans.