SOLID Principle By Example (O)

Open-Closed Principle (OCP)

Open for extension closed for modification.

Violates OCP

To fix above code, we can do something like this

Valid OCP

Now when we have change-request in requirements to add paypal method, all we have to do is adding another paypal class implements same PaymentInterface and thats it, so we extended(open for extension) our application with paypal but we didn’t modify(closed for modification) any of previous code.