This is a continuation of the SOLID. In the last post, I covered the S and now we will be continuing with the O. So if you didn't check the last post, feel free to click on the link: https://dev.to/sightlessdog/revisiting-the-s-in-solid-150e
“An entity should be open for extension, but closed for modification”
OO Software Construction
Closed for modification: This assumes that the module has been given a well-defined, stable description (the interface in the sense of information hiding).
we can achieve that by using a pattern, where high-level modules don't know anything about low-level details. The code is not rigid because nothing would recompile if we add new things, and the code is not fragile because you cannot break the code or let’s say the architecture doesn't let you break things.
But wait for a second, there's another client who doesn't have a cone but has Cube and wants to calculate the volume.
And as you can notice, this class (VolumeCalculator) isn't closed for modification. In order to extend it, we had to change it.
Meyer, B. (1997): Object-Oriented Software Construction, 2nd edition
Robert C. Martin “Principles of OOD”