Yesterday during an interview I was asked what DI and IoC in spring were. My reply was:
when a
class(A)
extends abstractclass(B)
or implementsinterface(B)
or create a object ofclass(B)
of any class in it, thenA
is said said to be dependent onB
. Injecting this dependency, i.e. injecting the object in costructor or in setter method is called DI and in this process control over creating object goes to the "outside world" like XML configuration, this inversion of control is IoC. DI is not necessary IOC. We can still have DI when there is no IOC.
The interviewer didn't agree with me - where was I wrong?
One more thing-
As we used
Super class reference variable
orcoding through interface
in constructor or setter method parameter.Is this any way related withDI
/IOC
or this is only to achieveloose coupling
?