0

I'm trying to understand DI. The below point highlights a drawback of NOT using DI.

"A component is vulnerable to change in its dependencies. If a dependency changes, the component might have to adapt to these changes. For instance, if a method signature of a dependency is changed, the component will have to change that method call."

Why I am confused : Even with DI applied, if the method signature of a dependency's method changes won't the corresponding Interface signature need to be updated accordingly? And therefore won't the higher level injected class also need to be updated to reflect the change to the Interface?

Thanks for reading.

onzymorg
  • 19
  • 8
  • The signature of a method defined in an interface should never change, once published. If a different signature is needed, you define a new method. – Tieson T. Feb 01 '19 at 07:55
  • Fair enough but even then, won't you need to update the higher level injected class with the new method that you have added to the interface? The point I'm making is that the higher level class is not immune to changes in the lower level class even when a DI framework is applied. Or am I mistaken? Thanks again. – onzymorg Feb 01 '19 at 10:51
  • 1
    Your "setup" doesn't change; that is, you still are just injecting the interface. Yes, if you want to use the new method, the injected class has to be updated, but it's not broken at any point, since the original method is still available – Tieson T. Feb 01 '19 at 16:16

0 Answers0