Chapter 11, Curbing Your Enthusiasm

1. What form of dependency injection-induced damage do you see most often?

For me, this is absolutely excessive parameters. After learning dependency injection and getting excited about it, it's easy to want to abstract and inject everything. It tends to make testing a lot easier as the responsibility of each object decreases. The downside is a lot of objects and too much injection.

If I find myself with too many dependencies, I will try to step back and check my object design, looking for single responsibility principle issues in particular.

 

2. Why is it important not to blindly apply dependency injection all the time?

Just because something is cool or new, doesn't mean it's the best tool for the job. We should always strive to fix the solution to the problem and avoid cargo cult programming when we can.

 

3. Does adopting a framework, such as Google Wire, eliminate all forms of dependency injection-induced damage?

Sadly, no. Given that it only supports constructor injection, it cannot even be applied in all situations. Beyond that, it can make the management of excessive parameters significantly less painful.

While that is a good thing, the fact that it alleviates the pain makes it less likely that we will feel the need to address the underlying issue.

 

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.216.151.164