Michael Feathers @mfeathers https://twitter.com/mfeathers/status/994661651466010624
Inheritance might be the most unjustly maligned language feature. The amount of effort that has been expended at the language level to tame it over the decades has been extraordinary. Java dropped multiple inheritance and offered interfaces to cut away some hazard. Scala introduced traits; Ruby introduced modules.
But you can use inheritance safely if you just follow a few guidelines.
- Only inherit to complete an abstraction. Abtract classes have empty spaces that you fill. Don't override anything concrete.
- Preserve client context. No existing client should be surprised by the behavior you add via a subclass. When you follow guideline 1 this is easy.
- Don't mix concerns in a hierarchy. The hierarchy is the unit of responsibility. Not the class.
That's it. You end up with shallow manageable hierarchies.