What is this Design Pattern?

Posted by Can't Tell on Stack Overflow See other posts from Stack Overflow or by Can't Tell
Published on 2014-06-04T08:25:36Z Indexed on 2014/06/04 21:25 UTC
Read the original article Hit count: 226

I read the Wikipedia articles on FactoryMethod and AbstractFactory but the following code doesn't seem to fit anywhere. Can someone explain to me what the following pattern is or if it is an anti-pattern?

interace PaymentGateway{
  void makePayment();
}

class PaypalPaymentGateway implements PaymentGateway
{
  public void makePayment()
  {
    //some implementation
  }
}


class AuthorizeNetPaymentGateway implements PaymentGateway
{
  public void makePayment()
  {
    //some implementation
  }
}

class PaymentGatewayFacotry{
  PaymentGateway createPaymentGateway(int gatewayId)
  {
    if(gatewayId == 1)
      return PaypalPaymentGateway();
    else if(gatewayId == 2)
      return AuthorizeNetPaymentGateway();
  }
}

Let's say the user selects the payment method using a radio button on an html page and the gatewayId is derived from the radio button value.

I have seen code like this and thought it was the AbstractFactory pattern but after reading the Wikipedia article, I'm having doubts.

© Stack Overflow or respective owner

Related posts about java

Related posts about design-patterns