Intro

The second principle of SOILID Principles of OOP. #Open-Closed refers to the principle that once an entity(module, class, function…etc.) is complete and functional, it should be closed Open for extension but Closed for modification.

Explanation

Whenever the behavior of the entity needs to be updated or modified, instead of going into it and hacking it apart, it ought to be extended and overridden.

Example use

This saves the headache of if else-if chains that check the type to determine appropriate behavior when utilizing them in production code,


References