Code Smell 11 - Subclassification for Code Reuse
Code reuse is good. But subclassing generates a static coupling.
- Favor composition.
- If hierarchy follows the principle behaves like then it is safe.
- Overriding can issue warnings when subclassing concrete methods.
- Deep Hierarchies (more than 3 levels) are also a clue of bad subclassing.
In legacy systems is very common to have Deep Hierarchies and method overriding, we need to refactor them and subclass by essential reasons and not implementative ones.
This article is part of the CodeSmell Series.