I was reading Wikipedia's definition of Dependency inversion principle, and it uses two terms High-level modules and low-level modules, which I wasn't able to figure out.
What are they and what does Dependency inversion principle have to do with them?
High-level modules contain the important policy decisions and business models of an application – The identity of the application. Low-level modules contain detailed implementations of individual mechanisms needed to realize the policy.
Definition of the Dependency Inversion Principle The general idea of this principle is as simple as it is important: High-level modules, which provide complex logic, should be easily reusable and unaffected by changes in low-level modules, which provide utility features.
High level module is the interface / abstraction that will be consumed directly by the presentation layer. Low level on the other hand are bunch of small modules (subsystems) help the high level do their work.
Low level classes are the simple workers that perform actions, while high level classes are the management class that orchestrate the low level classes. For example, if you have a class that reads bytes from a file and a class that calculates the CRC of bytes, they are low level classes because each performs an action.
The definition of those are given in the introductory sentence:
high level: policy setting
low level: dependency modules.
In laymen's terms: high level modules depend on low level modules, but shouldn't depend on their implementation. This can be achieved by using interfaces, thus decoupling the definition of the service from the implementation.
This is explained here: https://softwareengineering.stackexchange.com/a/419630
Low level modules are "low level" because they have no dependencies, or no relevant dependencies. Very often, they can be easily reused in different contexts without introducing any separate, formal interfaces - which means, reusing them is straightforward, simple and does not require any Dependency Inversion.
High level modules, however, are "high level", because they require other, lower level modules to work. But if they are tied to a specific low-level implementation, this often prevents to reuse them in a different context.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With