Learning Dependency Inversion Principle

Heads up... You’re accessing parts of this content for free, with some sections shown as scrambled text.

Heads up... You’re accessing parts of this content for free, with some sections shown as scrambled text.

Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.

Unlock now

Dependency Inversion

Dependency Inversion states that high-level modules shouldn’t depend on low-level modules, but both should rely on abstractions. You should work with abstractions rather than classes or concrete implementations. When you do this, your components become reusable. Changes in a low-level module do not affect any other module. That’s called loose coupling. The two main parts of this principle are:

Understanding the Importance of Dependency Inversion

Imagine you could only use a specific set of tires on your car, and if you ever needed to replace them, you’d have to stick to the same brand and model. That’d be quite inconvenient. However, fortunately, you can use any other tire that meets the required specifications. The same goes for the fuel you use in your car. You don’t have to go to a specific gas station to get the same brand of fuel every time. Instead, you can get the same type of fuel at various locations throughout the country.

See forum comments
Download course materials from Github
Previous: Implementing Interface Segregation Principle Next: Implementing Dependency Inversion Principle