There are appropriate uses of inheritance. For example, take an adapter which provides no-op implementation of an interface. In Kotlin, such an adapter must be made open
. Otherwise, the adapter would serve no purpose.
There are other examples of appropriate use of inheritance. For example, Android programs make regular use of inheritance. The main activity class must subclass Activity
.
Still, as the article points out, when enlarging the functionality of an existing class, composition is usually better than inheritance. Encapsulation is not broken.
Thank you for your comment. You have made a good point.