Effective Kotlin: Item 19 — Design and document for inheritance or else prohibit it
Kotlin makes a bold move by making all classes
final by default, prohibiting inheritance unless explicitly requested using the
open keyword. Sitting nicely in line with Joshua Bloch’s recommendation in Effective Java, it requires more thought by the developer should they wish to create a class appropriate for inheritance. After all, favour composition over inheritance.
Of course, there are times when having
final classes can be frustrating, not least when you use frameworks such as Spring…