Skip to content

PHP - Apply Factory Method Pattern#69

Open
ahmedkamaldabour wants to merge 2 commits intomahyoussef:mainfrom
ahmedkamaldabour:main
Open

PHP - Apply Factory Method Pattern#69
ahmedkamaldabour wants to merge 2 commits intomahyoussef:mainfrom
ahmedkamaldabour:main

Conversation

@ahmedkamaldabour
Copy link
Copy Markdown

This pull request introduces a new implementation of the Factory Method design pattern for payment processing in the codebase. It adds a set of classes and interfaces to support the creation and handling of different payment methods (Visa, MasterCard, American Express) in a scalable and maintainable way. Additionally, it updates the example usage in the main index file to demonstrate the new pattern.

Key changes include:

Factory Method Pattern Implementation:

  • Added the PaymentMethod interface, which defines the contract for all payment method classes, including methods for authorization, money transfer, fee calculation, and card details management.
  • Implemented concrete payment method classes: Visa, MasterCard, and AmericanExpress, each providing specific logic for their respective card types. [1] [2] [3]
  • Introduced the PaymentMethodFactory class, which creates instances of the appropriate payment method based on the card type provided.
  • Added the PaymentProcessor class, which uses the factory to process payments in a unified way, demonstrating the Factory Method pattern in action.

Example and Usage Updates:

  • Updated index.php to comment out the previous newsletter example and add a new example demonstrating how to use the PaymentProcessor and Factory Method pattern for payment processing.

ahmedkamaldabour and others added 2 commits October 28, 2025 03:25
feat: implement Factory Method pattern for payment processing
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant