Dependency Injection

Handing a class the things it needs instead of letting it create them.

What is Dependency Injection?

Dependency injection means giving a class the things it needs (usually through its constructor) instead of the class creating them itself. It makes code easier to test and to change.

// The caller decides which sender to use
var service = new OrderService(new FakeEmailSender());

Level: Freelancer · More OOP terms at this level

Updated