3 ms·
But that's not true at all. The genesis for DI was nothing close to that (as I learned it). DI's main purpose isn't testing, it's flexibility. DI isn't there so
by DatBear 12y ago
But that's not true at all. The genesis for DI was nothing close to that (as I learned it). DI's main purpose isn't testing, it's flexibility. DI isn't there solely for testing, or if it is, you're probably missing the point of it.
- icedchai 12y agoRight. However, in many DI-heavy apps I've seen, nobody ever makes use of that flexibility. Otherwise it's just extra, unnecessary complexity, sitting around in verbose XML files and annotations, causing code clutter. These are "enterprise" Java apps with Spring, etc.
- revscat 12y agoThis has been my experience as well. The core of Spring -- IoC/DI -- solves a problem that is largely of its own making. I've had better luck and cleaner code without it than with it.
- DatBear 12y agoI personally don't see how a couple parameters in the constructor are adding so much complexity that you'd be better off without DI. A good DI container can make it much easier to follow a pretty good amount of general best practices. Single Responsibility, DRY, and Open-Closed Principle to name a few.