Prefer Composition over Inheritance
Inheritance is a powerful feature, but it is designed to create a hierarchy of objects with the is-a relationship.
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.