And fundamentally, inheritance is the wrong tool for reuse. Providing lots of small methods to make for improved reuse through inheritance is an equally wrong approach.
I wanted to write about that a little more.
Cases where inheritance has worked out well: when I can arrange for a base class to provide a lot of functionality, and one or maybe two abstract methods overridden in the subclass. Essentially, this comes down to “using inheritance as a mechanism to implement a strategy for some small, but critical, polymorphic bit.” Or perhaps, “making a DSL by providing operations in a base class, then implementations in child classes.”
Probably the most accessible example of this is PHP’s FilterIterator which does little more than wrap a regular Iterator with an
accept()
method.Notably, it doesn’t extend anything itself to do this. It composes another iterator and exposes that through the OuterIterator interface.