Challenge: Implementation of the Design pattern Factory Method.
In a virtual store we have only one payment method, via Paypal. At a certain point, clients began to ask to implement Pagseguro.
This became a problem as all the payment code is implemented inside the Paypal class.
Most of your code is nested and adding the new payment method in there would make the code full of conditionals and every time you would implement a new payment type it would make it even more complicated.
The factory method suggests that you replace the creation of the Paypal class with a special Factory function. The result of this creation, we call product.
For this we use a payment method interface where it will implement exactly the same methods.
Furthermore, a class is an abstract object creation class so that we can extend and generate concrete classes for each of the payment methods.
This project is under the MIT license. For more information, access the file LICENSE.