Confused about this factory, as it doesn't look like an Abstract Factory nor Factory Method
- by Pin
I'm looking into Guice and I've been reading its documentation recently.
Reading the motivation section I don't understand the factories part, why they name it that way. To me that factory is just a wrapper for the implementing class they want it to return after calling getInstance().
public class CreditCardProcessorFactory {
private static CreditCardProcessor instance;
public static void setInstance(CreditCardProcessor creditCardProcessor) {
instance = creditCardProcessor;
}
public static CreditCardProcessor getInstance() {
if (instance == null) {
throw new IllegalStateException("CreditCardProcessorFactory not initialized. "
+ "Did you forget to call CreditCardProcessor.setInstance() ?");
}
return instance;
}
}
Why do they call it factory as well if it is neither an abstract factory nor a factory method? Or am I missing something?
Thanks.