Search code examples
design-patternszend-framework2observer-pattern

Right Pattern to use


I want to create a Payment Module, this module is going to have a form where the user can pay a product, after the payment is done I want to save the payment info on several db tables. I want to use this module in different companies each company handles the persistent data differently ex one saves the data in one table the others in two or tree tables, my idea was to implement an observer pattern where the publisher (being the payment class) can push payments info into the table classes (being the subscribers) so this ones can save the data into their tables.

Is this the correct pattern to use? any suggestions?

Thanks


Solution

  • If I understand you correctly, you should have a black box implementation of the Response from the Payment provider and at one time this module could be used by one company. Your idea looks nice, indeed. The suggestion by me could be using of Command design pattern. For each type of Response : ERROR, DECLINED PAYMENT, CANCELED BY USER PAYMENT, SUCCESSFUL PAYMENT and etc. each company will have their own implementations. And each concrete command will implement different payment status . Like SuccessfulPayment, CanceledPayment ... implements the interface ICOmmand. These specific implementations you could remain to the companies. For you the only one thing required is the result by company's specific processing of the payment provider's response. You will use the ICommand interface for example in order to continue the processing in your own business logic.