Take a look at Gimlet <https://code.google.com/p/google-gimlet/>. It uses
Guice and provides better abstractions for the robot legs problem. I've
used it quite a bit.
Client code looks like this:
public class RobotLegModule extends AbstractModule {
@Override protected void configure() {
bind(Sneaker.class).to(NewBalanceSneaker.class);
install(new LegModuleBuilder()
.bind(RobotLeg.class)
.using(Sneaker.class)
.build()));
}
}
On Wednesday, January 14, 2009 1:52:38 PM UTC-6, Esko Luontola wrote:
>
> Would it be possible to solve the "robot legs" problem like this?
>
> bind(Leg.class).annotatedWith(Left.class).to
> (Leg.class).injecting(LeftFoot.class);
> bind(Leg.class).annotatedWith(Right.class).to
> (Leg.class).injecting(RightFoot.class);
>
> The Leg class has a constructor parameter of type Foot and possibly
> also other parameters. The "injecting" method is used to define the
> Foot implementation that will be injected to Leg.
>
> Here are some issues that will still need to be thought about:
>
> - It should be possible to specify multiple explicit dependencies, for
> example "injecting(LeftFoot.class, LeftKnee.class)" or "injecting
> (LeftFoot.class).injecting(LeftKnee.class)". In the latter case it
> would be possible to also specify the dependencies as object instances
> or providers, by having overloaded "injecting" methods or
> "injectingInstance", "injectingProvider" etc. methods.
>
> - How to handle the cases where Foot is not a direct dependency of
> Leg, but instead the dependency of one of Leg's dependencies?
>
> - What would be the best name for the "injecting" method? One other
> possibility is "usingDependencies".
>
>
--
You received this message because you are subscribed to the Google Groups
"google-guice" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/google-guice/-/eftjQc8OY9IJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-guice?hl=en.