4 ms·
I used Java for a while and then switched to Kotlin as my daily tool, and one interesting thing that I found was that Kotlin prevents inheritance by default, an
by vishnuharidas 2y ago
I used Java for a while and then switched to Kotlin as my daily tool, and one interesting thing that I found was that Kotlin prevents inheritance by default, and the developer has to explicitly mark a class as "open" to allow inheritance. Eventually I stopped using inheritance and now prefer to use composition over inheritance wherever possible.
- AtlasBarfed 2y agoI haven't used kotlin. How does it help it? So the kicker in imperative OO for composition is that the class you are composing has some state / instance vars. How do you include methods that can view/update those instance vars? Sure it's easy to compose with static/pure functions. Do you enclose the instance vars in holder classes and pass those holders to the composition implementation class in it's method signature? In the end, inheritance or composition is about constructing a class /struct/whatever with a given set of expected signatures with some ideally documented guidance on any intricacies.