Dagger: A Fast Dependency Injector for Android and Java
Recorded at:
DI - an Anti-Pattern?
by
Fred Amiter
Re: DI - an Anti-Pattern?
by
Nils Kilden-Pedersen
What's worse is, there's no point to this hand-waving. It buys you absolutely nothing, and it costs you code clarity and pollutes your classes with annotation dependencies.
Let's take the DripCoffeeModule and remove the annotations. Voila, you just have a perfectly useable class for resolving DI, but without the magic:
class CoffeeApp {
public static void main(String[] args) {
DripCoffeeModule mod = new DripCoffeeModule();
Heater heater = mod.provideHeater();
Pump pump = mod.providePump(new Thermosiphon(heater));
CoffeeMaker cm = new CoffeeMaker(heater, pump);
coffeeMaker.brew();
}
}
Much, MUCH, easier.
Re: DI - an Anti-Pattern?
by
Tony Chow
Re: DI - an Anti-Pattern?
by
Nils Kilden-Pedersen
Re: DI - an Anti-Pattern?
by
Tony Chow





Hello stranger!
You need to Register an InfoQ account or Login to post comments. But there's so much more behind being registered.Get the most out of the InfoQ experience.
Tell us what you think