Dependency injection

So, what exactly is dependency injection? It turns out to be something really simple—every single class that has an object as a parameter in their constructor is actually an example of a dependency injection. The reason is that the dependency is injected into the class rather than instantiated inside it. Developers should actually try to use this kind of approach instead of creating objects inside a constructor. There are many reasons for this, but one of the most important ones is the fact that components can become tightly coupled and practically untestable.

Dependency injection, however, could degrade the code quality if implemented using constructor parameters. This would make constructors take a large number of parameters ...

Get Scala Design Patterns - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.