Code Smell: Inheritance Abuse
Posted
by
dsimcha
on Programmers
See other posts from Programmers
or by dsimcha
Published on 2010-10-16T17:27:17Z
Indexed on
2011/03/19
0:18 UTC
Read the original article
Hit count: 333
It's been generally accepted in the OO community that one should "favor composition over inheritance". On the other hand, inheritance does provide both polymorphism and a straightforward, terse way of delegating everything to a base class unless explicitly overridden and is therefore extremely convenient and useful. Delegation can often (though not always) be verbose and brittle.
The most obvious and IMHO surest sign of inheritance abuse is violation of the Liskov Substitution Principle. What are some other signs that inheritance is The Wrong Tool for the Job even if it seems convenient?
© Programmers or respective owner