Confused about this factory, as it doesn't look like an Abstract Factory nor Factory Method

Posted by Pin on Stack Overflow See other posts from Stack Overflow or by Pin
Published on 2010-05-25T11:56:29Z Indexed on 2010/05/25 12:01 UTC
Read the original article Hit count: 418

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.

© Stack Overflow or respective owner

Related posts about java

Related posts about design-patterns