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).…