Composition over Inheritance
The cluster debates the use of inheritance in object-oriented programming, with most comments advocating for composition, interfaces, traits, or other alternatives over inheritance due to issues like tight coupling and fragility.
Activity Over Time
Top Contributors
Keywords
Sample Comments
Alternate view:https://en.wikipedia.org/wiki/Composition_over_inheritance
Inheritance is not necessarily the wrong abstraction, too.
Inheritance is just a tool to mostly avoid. It tightly couples different class implementations. So will make later refactors error-prone and tend to scatter logic. It's misunderstanding OO as messaging between objects.Using composition or lay out data differently may yield designs with more desirable properties. There's no one answer and it depends.
Inheritance is likely the worst idea of OOP's implementations.The right way to achieve the same and better results is interfaces / typeclasses / traits. They work pretty well in languages from Rust and Haskell to Typescript, Kotlin, Java, and even Go. (Go is a bit special because you don't even have to declare that your class implements an interface, as long as it actually has a set of methods with right signatures.)Ideally, all public methods should only describe param
Inheritance is not always the right solution.
Inheritance isn't terrible if you design your classes properly.
No, there's a time and place for inheritance, just not as often as composition.
Inheritance is a concept of OOP not programming itself. And yes I much prefer composition.
Inheritance is usually bad, but encapsulation and composition are good.
Inheritance is not essential to OO; it is merely a method of sharing code.