Dependency Inversion Principle

noun

say it: “dih-PEN-dun-see in-VUR-zhun PRIN-suh-pul” /dɪˈpɛndənsi ɪnˈvɜrʒən ˈprɪnsəpəl/

The principle that high-level code and low-level details should both depend on a promise, and that the promise belongs to the high-level code.

What is Dependency Inversion Principle?

The Dependency Inversion Principle says important code should depend on interfaces, not on specific tools. OrderService depends on IEmailSender, not on a particular email company.

public class OrderService
{
    private readonly IEmailSender email;   // an interface, not SendGridClient
    public OrderService(IEmailSender email) => this.email = email;
}

In a sentence

  • “The dependency inversion principle turned the arrows around: the email server now keeps a promise the report-card sender owns.”

Level: Freelancer · More OOP terms at this level

Updated