This is a mirror of official site: http://jasper-net.blogspot.com/

Dependency Injection for Android with Google’s Roboguice

| Tuesday, June 14, 2011
For most developers, writing Android apps means writing a ton of Java. On large projects, trying to keep patterns straight can be pretty difficult. Useful frameworks for Android are few and far between, which leaves the programmer to pick up a lot of the details of the system. Far too many bugs are created this way.

The other day, I came across Roboguice, a port of Google's Guice framework over to Android. If you've never heard of it, it’s a simple framework to streamline Dependency Injection within Android. The framework still seems to be a hidden gem. I couldn’t find many developers that even knew it existed.

What is Dependency Injection, really?

In short, Dependency Injection is a way to decouple specific types of objects in your code. It allows your program to be far more modular with minimal extra effort. If you have ever heard of the Factory, then you have at least a faint idea of what Dependency Injection is.

What is Roboguice… and what’s up with the name?

Roboguice is actually just an implementation of Google's Guice within Android – sorry, I don’t have a clue why they picked the name. It lets an application have all the benefits of Dependency Injection with just a handful of lines of code. In Google's words, "Guice alleviates the need for factories and the use of new in your Java code." Like everything else Google related, an IO video gives a pretty good idea about it.

Posted via email from Jasper-net

0 comments: