A framework for dependency injection
By Tobias Lütticke & Christian Meder
Google Earth and Google Maps are evidence of the delight Google takes in continual innovation. Its in-house developers haven't stopped yet, and a new member of their family of products is Guice, an open-source framework that's a lean alternative to Spring.
When AdWords, Google's internet advertising application, was being extended, Google Guice was devised in order to solve the team scaling problems that arise when projects involve more than a hundred developers. It's an open-source framework for dependency injection (DI). Although such DI frameworks as the popular Spring  are already well established, Google wanted to use especially lightweight software of its own for in-house software development (see "Loose coupling").
Generics and Annotations from Java 5 are essential components of this framework . Besides integrating Spring, Guice supports its own scopes (see Glossary) and aspect-oriented programming (AOP). Its ability to inject static attributes and manage circular references completes the picture.
Here's a sample holiday planning application, booking a hotel (Figure 1). The planner object (caller) addresses a
booking interface, behind which specific implementations (target objects) are hidden. A mock (dummy) object is used here so that the genuine target system doesn't have to be queried incessantly during development. For productive operation, the developer needs to be able to simply switch over to the genuine target.
The framework is intended to be especially lean and permit a massive reduction in boilerplate code, freeing the developer to work on essentials rather than writing tediously repetitive code. To make this possible, Guice concentrates exclusively on a high-performance implementation of DI, and is correspondingly slimmed down in terms of the size of JAR files and the amount of memory it consumes. Guice doesn't stores dependencies in central XML files, but in the Java code.