The Strategy pattern enables selecting an algorithm's behavior at runtime by encapsulating algorithms in separate classes. This allows the client to switch strategies without changing its own code.
The Context class maintains a reference to a Strategy object and delegates the execution to it. It controls which strategy is used.
Adding new algorithms as separate Concrete Strategy classes and registering them dynamically allows scaling without modifying the Context, adhering to open/closed principle.
The Strategy pattern increases the number of classes because each algorithm is a separate class, which can make the system more complex to manage.
The client chooses the payment method, the Context sets the appropriate Strategy, then delegates the payment processing to that Strategy.
