There are a few things I just can’t live without in projects these days. These include stuff like Functions, Predicates, filtered and transformed Iterables, the immutable collections implementations, and a raft of other stuff from the Google commons. If it wasn’t open-source, writing java code these days would feel like working with flint and stone.
Also included in that how-do-people-live-without-this-stuff list is decent dependency injection.
I didn’t notice until I was a long way into the project that Guice now has support for Android. At the moment, I’m using Guice 2.0 without AOP, Multibindings support, and assisted inject, and quite frankly, the code is almost instantly better for it. Constructors now only contain what the local object needs to use to do its job, and everything is an awful lot more readable.
It’s also nice not to have to pass around awareness of the fact that Android’s context classes are a pig’s ear of methods. There’s nothing wrong with using composition instead of inheritance, folks; your application classes shouldn’t need to be a combination of implementations every single interface in the SDK. That’s not discoverable, that’s just a wall of noise.
Anyways, four hours of un-hardwiring class construction resulted in a much easier second refactoring to start splitting foreground from background services, which took all of an hour and only involved creating a new module for the new service class, and poof!
I still wonder how people get on without DI, and why on earth this isn’t core java yet. Mind you, I wonder that about Joda, too. And closures. And just about any other modern feature that doesn’t make it into the now-overpoliticized trial by fire of the JDK.