SOLID & Design Patterns Interview Question #135

What is dependency direction and why does it matter?

Anti-Patterns, Refactoring, DI Lifetimes & Senior Design Scenarios Senior Advanced

Quick Interview Answer

Dependency direction describes which modules know about and reference other modules. Stable business policy should generally not depend directly on volatile infrastructure details.

Detailed Explanation

Dependency direction describes which modules know about and reference other modules. Stable business policy should generally not depend directly on volatile infrastructure details.

Controlling dependency direction makes frameworks, databases, and external integrations easier to replace or test. Dependency Inversion uses abstractions to reverse a source-code dependency when the policy layer should own the contract.

Code Example

Application -> IEmailSender
                  ^
                  |
Infrastructure -> SmtpEmailSender

// Core owns the required abstraction.