1
我有代码看起来像FF:依赖注入使用情况
Interface i;
if (someCondition) {
ImplementationA a = new ImplementationA();
a.setFieldA(someValueA);
a.setFieldB(someValueB);
i = a;
} else {
ImplementationB b = new ImplementationB();
b.setFieldC(someValueC);
i = b;
}
// Do something with i.
我的问题是:
- 我应该在这里使用依赖注入,或者这是超出范围技术?
- 如果我应该在这里使用依赖注入,我该如何使用Google Guice来实现它?