Before our previous article, our code to model a mechanic used to look like this:
class Mechanic {
private final Engine engine = ServiceLocator.getCar().getEngine();
public void fixEngine() { /* … */ }
}
Luckily, we applied some dependency injection, resulting in nicer code: testable, and with an explicit dependency on the ServiceLocator:
class [...]


