Dependency Inversion Principle: Understanding how both low level components and high level components depend on abstractions

softwareengineering.stackexchange https://softwareengineering.stackexchange.com/questions/235025

Question

I'm learning about the Dependency Inversion Principle. It states that:

High level modules should not depend upon low-level modules. Both should depend upon abstractions.

For a while I tried to understand what it means that both the high level components and the low level components, rely on the abstractions and are dependent on them.

I'm assuming both should depend on the same abstraction in some way. Please correct me if this is wrong.

I have come to some conclusion about what this means. Please confirm if this is accurate.

enter image description here

"The high level components are dependent on the abstraction" - Meaning:

The high level components talk to an interface to communicate with the low level components, instead of communicating with concrete low level components directly. The low level components implement this interface.

"The low level components are dependent on the abstraction" - Meaning:

The low level components are defined and designed in the terms of the interface. They are designed to fit the interface. They are dependent on the interface, in the way that the interface defines how they are designed. (Often low level classes implement that interface).

This way, both the high level components and the low level ones are 'dependent on the abstraction', but in different ways.

Is this a good understanding?

Was it helpful?

Solution

Your understanding of the concept is very accurate.

Pointing out exceptions, special cases or philosophical minutiae right now would be diverting you from your present clarity of concept.

I would suggest, though, you use UML symbols:

enter image description here

  • Open arrow : uses
  • Closed arrow: inherits or implements
  • << name in brackets >> : interface or abstract class

OTHER TIPS

Yes, many people think of software construction as in building construction. The DB is the "foundation" the DAL sits on top of it, the Business Layer Sits on the DAL, the UI sits on the Business Layer...

Instead think of it as a hanging mobile. Where the "layers" hang from a common anchor. UI and Business Layer both hang from the Business Interface, Business Layer and DAL both hang from the DAL interface, DAL and Database connect through the DB Interface.

Licensed under: CC-BY-SA with attribution
scroll top