# Effective Kotlin Item 36: Prefer composition over inheritance

DevFeed: [Effective Kotlin Item 36: Prefer composition over inheritance](<https://devfeed.tech/articles/effective-kotlin-item-36-prefer-composition-over-inheritance-39274.md>)

Original publisher: [Read original article](<https://kt.academy/article/ek-composition>)

Published: 2021-04-25T00:00:00Z

Content type: article

Language: en

Sources: [Kt. Academy](<https://devfeed.tech/sources/kt-academy.md>)

Topics: [Inheritance](<https://devfeed.tech/topics/inheritance.md>), [Object-oriented programming (OOP)](<https://devfeed.tech/topics/oop.md>), [Kotlin](<https://devfeed.tech/topics/kotlin.md>), [reuse](<https://devfeed.tech/topics/reuse.md>), [superclass](<https://devfeed.tech/topics/superclass.md>)

Tags: [approach](<https://devfeed.tech/tags/approach.md>), [behavior](<https://devfeed.tech/tags/behavior.md>), [hierarchy](<https://devfeed.tech/tags/hierarchy.md>), [inheritance](<https://devfeed.tech/tags/inheritance.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [object](<https://devfeed.tech/tags/object.md>), [oop](<https://devfeed.tech/tags/oop.md>), [reuse](<https://devfeed.tech/tags/reuse.md>), [superclass](<https://devfeed.tech/tags/superclass.md>), [workshop-learning-programming](<https://devfeed.tech/tags/workshop-learning-programming.md>)

## AI overview

The article argues that inheritance should primarily model a clear "is a" relationship and can be problematic when used mainly for code extraction or reuse. It presents class composition as a safer and more explicit alternative, while acknowledging that composition requires additional code.

## Source excerpt

Years of OOP made us overuse inheritance. Instead, we should more often use a composition that is safer and more explicit. More often, but not always...