Finding the High-Level and Low-Level modules in dependencies for applying Dependency Inversion Principe

dependencies, dependency-inversion, design-patterns

Solution

This is how usually I refer them:

High Level Module --> this module represent more business aspect rather than technical aspect. It can be refered as an abstraction rather than implementation, and usually achieved through interfaces.

Some example maybe: `RegisterAccount`, `PostAnswer`, `PostQuestion`, `AddComment`, `InsertComment`.

Since Low Level Module represent more technical aspect rather than the business aspect. Say for example we take the `InsertComment` HLM. The LLM should be:

- Open database connection

- Execute insert statement

- Close database connection

A High Level Module can be a Low Level Module in another context. Taking another example, `AddComment`'s LLM should be:

- Validate the comment (e.g. 15 char min) --> this will be another HLM

- Insert comment to database --> this will be another HLM (`InsertComment`)

- Add notification to involved user --> this will be another HLM

The same apply for other HLM as well.

Problem

The Dependency Inversion Principle say: - High-level modules should not depend on low-level modules. Both should depend on abstractions. - Abstractions should not depend upon details. Details should depend upon abstractions. How can I practically find the High-level and the Low-level modules in my applications, is there any clear definition for them?

Original source