What is this Design Pattern?
- by Can't Tell
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.