That's great, thank-you! I'm going to try that... it would greatly
simplify the amount of code.

On Sep 2, 1:58 am, Dan Godfrey <[email protected]> wrote:
> If there's a one-to-one mapping between the Types and calculators and
> the calculators can be singletons, you could have used a MapBinder.
> However you still need the CalculatorFactory or a CalculatorRegistry
> (as it's not actually creating anything anymore), it's a bit smaller
> and a lot less boilerplate to maintain.
>
> public class CalculatorModule extends AbstractModule {
>    protected void configure() {
>      MapBinder<Types, ICalculator> mapbinder
>          = MapBinder.newMapBinder(binder(), Types.class,
> ICalculator.class);
>      mapbinder.addBinding(Types.A).to(ACalculator.class);
>      mapbinder.addBinding(Types.B).to(BCalculator.class);
>      mapbinder.addBinding(Types.C).to(CCalculator.class);
>    }
>  }
>
> @Singleton
> public class CalculatorFactory {
>     private final Map<Types, Calculator> calculators;
>
>   �...@inject
>    public CalculatorFactory(Map<Types, Calculator> calculators) {
>         this.calculators = calculators;
>     }
>
>     public ICalculator create(UserGroup group) {
>          calculators.get(group.getType);
>     }
>
> }
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"google-guice" group.
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to