Open-Closed principle is one of the five SOLID principles of object-oriented design. It states that "software entities (classes, modules, functions, etc.) should be open for extension, but closed for modification".
But recently most programming languages are providing a way to finalize classes such that it won't be inherited in future by providing keywords such as final
. Some languages like Kotlin have their classes by default final (aka opt-in open).
I have also read some articles which states that interface inheritance must be preferred over implementation inheritance with valid reasoning like fragile base class problem. But OCP tells that classes should be open for extension. So should I consider declaring my classes open? or final? Which is a good practice in general?