Strategy Design Pattern: Online Payment Gateway

๐Ÿ“˜ Scenario:

Imagine you are developing an e-commerce app. When a user checks out, they can choose from different payment methods:

Each method has a different algorithm/logic for processing payments.

Problem:

If you try to handle all payment methods in a single PaymentProcessor class using if-else or switch, your code will:

๐Ÿ’ก Strategy Pattern Solution:

We define a common interface for all payment methods. Then, we plug in the appropriate payment strategy at runtime.

UML Diagram:

UML Diagram of Strategy Pattern for Payment System

Output:

Paid Rs. 1500.0 using Credit Card.
Paid Rs. 5000.0 using PayPal.
Paid Rs. 12000.0 using Cryptocurrency.
๐Ÿ”— View Code on GitHub

๐Ÿ›’ Online Store Checkout

๐Ÿงพ Payment summary will appear here...