Open/Closed Principle
Under OCP, adding a new payment option means writing a new class that implements the interface, leaving original code untouched. A strategy-based design supports extension by adding new classes instead of modifying existing code. Switch st…
3 sources - 12 claims
Under OCP, adding a new payment option means writing a new class that implements the interface, leaving original code untouched. A strategy-based design supports extension by adding new classes instead of modifying existing code. Switch statements invert the Open/Closed relationship by requiring modification of existing code to extend functionality. The Strategy and Factory patterns directly satisfy the Open/Closed Principle by introducing behavior through new objects rather than code modification. The Open/Closed Principle is one of the five SOLID principles of software design. The Open/Closed Principle states that code should be open for extension but closed for modification. The Open/Closed Principle states that software entities should be open for extension but closed for modification, with new behavior added by writing new code rather than editing existing code. A registry-enabled strategy system can automatically discover, register, and dispatch to new strategies. Directly editing a PaymentProcessor class each time a new payment gateway is needed violates OCP and risks breaking existing payment logic. Changing a method to add new behavior violates the open/closed principle w…