I've seen various flavors of this question from other people but still
don't feel like I understand how to solve it. Any input would be
greatly appreciated.
How can I use Guice to create the different instances of the
calculators? Or in this case, do I even NEED to use Guice to create
the calculator instances since this is a factory. Guice would just
inject the needed dependencies to the factory. I'm confused about
"Guice replacing all instances of 'new'" in our code. Does that hold
true everywhere or are there places where you would expect to 'new' a
class?
public class CalculatorFactory {
private final Map<UserGroup, ICalculator> m_calculators;
public CalculatorFactory(SomeObject dependency1, SomeObject
dependency2, SomeObject dependency3) {
m_calculators = new HashMap<UserGroup, ICalculator>();
m_calculators.put(UserGroup.A, new ACalculator(dependency1,
dependency2, dependency3);
m_calculators.put(UserGroup.B, new BCalculator(dependency1);
m_calculators.put(UserGroup.C, new CCalculator(dependency1);
}
// Depending on which group a user belongs to,
// a different type of calculator will be returned
public ICalculator loadCalculator(UserGroup userGroup) {
return m_calculators.get(userGroup);
}
}
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---