Better Engineers

Better Engineers

Prefer Composition over Inheritance

Inheritance is a powerful feature, but it is designed to create a hierarchy of objects with the is-a relationship.

Better Engineering's avatar
Better Engineering
Mar 23, 2023
∙ Paid
2
1
Share

Inheritance is a powerful feature, but it is designed to create a hierarchy of objects with the is-a relationship. When such a relationship is not clear, inheritance might be problematic and dangerous. When all we need is a simple code extraction or reuse, inheritance should be used with caution, and we should instead prefer a lighter alternative: class…

Keep reading with a 7-day free trial

Subscribe to Better Engineers to keep reading this post and get 7 days of free access to the full post archives.

Already a paid subscriber? Sign in
© 2025 Dev Dhar
Privacy ∙ Terms ∙ Collection notice
Start writingGet the app
Substack is the home for great culture