views:

40

answers:

1

I'm building a software product, in which the customer will be able to configure their system to use any one of 3 or 4 pre-integrated payment gateway vendors. (eg: PayPal, Authorize.net, etc).

The customer will log into the application, navigate to settings, select which vendor they have an account with, enter the relevant account information and save. Then, and payment transactions processed will go through that particular payment gateway vendor API.

I'm looking for a pattern to use to abstract this away from the actual function of making a payment. That is, when a user makes a payment, a Payment object is instantiated, then Payment->validate() is called, then Payment->save() is called. I want this Payment class to abstract away the details of which particular vendor will be used on the backend.

So this Payment class will need to be able to determine the configured payment gateway vendor (done, not asking for help with that), then instantiate an object of that particular payment gateway class, and call relevant methods.

So what I'm asking is, is there a typical design pattern for this type of thing, what is it called, and do you have links to good material on this. I'm not looking for "help me write this code" type of information, I'm looking for "teach a man to fish" type of information :-)

Thanks.

+1  A: 

I would use the Strategy Pattern from GoF book. Instead of Payment->save() you write an AbstractPaymentService that provides the validate(payment) and save(payment). For each payment service type you then implement the AbstractPaymentService (e.g. PaypalPaymentService).

bertolami
Thanks bertolami. What's the full name of the GoF book?
Mike King
I think I answered my own question: The "Gang of Four" book "Design Patterns: Elements of Reusable Object-Oriented Software".
Mike King

related questions