# What Dependency Injection Solves — Advanced Java

Source: https://www.geekswithgeeks.com/en/advanced-java/adv-di-explained

> See the tight coupling and untestable code that manual object wiring with new creates, and how injecting dependencies through constructors fixes both.

## Don't build your own tools

A carpenter doesn't forge their own hammer — they're handed one. A class shouldn't forge its own collaborators with `new` either; it should be handed (**injected**) whatever it depends on, and just describe what it needs, not how to build it.

## Coupling and testability

`class OrderService { private EmailSender s = new SmtpSender(); }` hard-codes `SmtpSender` — you can never substitute a fake in a test, or swap providers without editing this class. Injecting an `EmailSender` through the constructor lets tests pass a stub and production wire a real one.
