Concept · Core

Dependency Inversion (D)

High-level policy shouldn’t depend on low-level details. Point BOTH at an abstraction — and watch the dependency arrow flip.

Asked atAmazonNetflixUberMicrosoft
step 1 / 8
1/2Depending on a detail
new EmailSender()
NotifService
- sender: EmailSender
+ notify(msg)
EmailSender
+ sendEmail(msg)
Depending on a detail
1class NotificationService {
2 EmailSender sender = new EmailSender(); // concrete
3 void notify(String m){ sender.sendEmail(m); }
4}

NotificationService is the high-level policy — it decides WHEN to notify.