3 ms·
I believe you got the D wrong. Dependency Inversion is not just about slapping an interface in between two components. It's about inverting the dependency. Let
by Izmaki 7y ago
I believe you got the D wrong. Dependency Inversion is not just about slapping an interface in between two components. It's about inverting the dependency. Let me explain:
Picture that we have two components, a main component "Master" and a subcomponent "Slave". What you seem to be saying is that we should have an interface between the two so that Master uses an "ISlave" interface that the Slave maintains (the developers of the subcomponent) instead of using Slave directly.
Dependency Inversion however dictates that you should invert this dependency so that Master dictates which functionality Slave should implement. That is, Master should have an ISlave interface (or an "IDelegation" or similar new name) that Slave (!) is required to fulfil. There is a small but very important difference between the two directions of the dependency arrow. One of the main points is that with Dependency Inversion it is the main component that is in charge of functionality instead of the main component having to work with the functionality exposed by the subcomponent.
- s188 7y agoNice. That's a really useful way of looking it it. I'll definitely commit that to memory.