DeboraZandonai / FactoryMethod

Implementation of the Design pattern Factory Method.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

πŸš€ Factory Method πŸš€

πŸ’» Project proposal

Challenge: Implementation of the Design pattern Factory Method.

The problem

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 solution

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.

πŸ“ License

This project is under the MIT license. For more information, access the file LICENSE.

Made with ❀️ by Debora Zandonai

About

Implementation of the Design pattern Factory Method.


Languages

Language:TypeScript 100.0%