Why Dependency Injection or Service Locator?
Hi,
Difference between a Depency Injection(DI) and doing an interface based operation as mentioned below :-
IA ia= new A()
ia.getData();
Here I am directly using an interface IA to instantiate A() which implements IA. This is what normally we use before the use
of the DI or Servicelocator.Using the DI will ensure that you will create a setter or interface dependency for your interface
and make use of it.Apart from that DI does have an advantage when you use any mock framework as these mock frameworks are based on DI,
is there any other advantage? Why IA ia= new A() is not used often? as we are handling the dependency based on the interface reference rather than instantiating
any concreate class. Hence it should be used more often right? Please clarify.
Thanks.