Menu

1 / 2

How I finally understood the Dependency Inversion Principle

DEV Community: typescript·Christian Vasquez·about 12 hours ago
#XWeB6r2i
#devtotypescript#devto#dev#order#orderservice
Reading 0:00
15s threshold

The Intro

Last stop. We made it to the D : the Dependency Inversion Principle.

This one is special because the other four kind of lead here. SRP gave us small classes. OCP taught us to add instead of edit. LSP and ISP gave us honest, tiny interfaces. DIP is where we decide who points at whom .

Buckle up, it's the one that changes how your main.ts looks forever.

The What

The definition has two parts:

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

Abstractions should not depend on details. Details should depend on abstractions.

Four sentences that use "depend" five times. Cool cool cool.

Plain version: your business logic should not import your database driver. The important stuff (orders, invoices, rules) should sit at the top and know nothing about the plumbing (Postgres, Stripe, the file system).…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.