Question: A payment system allows different types of payment methods ( credit card, PayPal, etc. ) . The PaymentProcessor class handles all the payment logic. Each

A payment system allows different types of payment methods (credit card, PayPal, etc.). The PaymentProcessor class handles all the payment logic. Each time a new payment method is introduced, the class must be modified to add a new payment type.
Which principle is being violated here, and how can you refactor the code?
Open-Closed Principle (OCP); by creating a new payment method class for each payment type and using an interface or abstract class for the payment processor.
Single Responsibility Principle (SRP); by separating payment methods into different classes.
Liskov Substitution Principle (LSP); by ensuring that each payment method can substitute another without changing the program behavior.
Dependency Inversion Principle (DIP); by depending on high-level abstractions instead of low-level modules.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!