I'll Be Backend
Principles

Dependency Inversion Principle: Let the Policy Own the Interface

The Dependency Inversion Principle says business rules should not depend on technical details: the rule declares the interface it needs, in its own words, and the details implement it. These lessons take a web shop's receipt service that creates and calls a mail client itself, so switching receipts to text messages edits the receipt rule in three places, and refactor it until text messages arrive as one new class.

Pick your language

When to use it

Use it when

A policy calls a detail that changes on its own schedule, like mail, text messages, storage or a payment vendor.

Skip it when

The class you call is stable, with no second version in sight, like String or List. An interface there only adds a name.

Spot it by

A business class that creates its own mail, database or HTTP client, or an interface whose methods copy a vendor API (to, subject, body) instead of what the caller needs.