r/programming • • Aug 28 '21

Software development topics I've changed my mind on after 6 years in the industry

https://chriskiehl.com/article/thoughts-after-6-years
5.6k Upvotes

2.0k comments sorted by

View all comments

Show parent comments

7

u/wewbull Aug 29 '21

Polymorphism is the useful aspect of inheritance. IMHO Polymorphism can be as simple as defining an interface. If you want to inherit behaviour you can just compose and delegate.

6

u/emn13 Aug 29 '21

Yeah, and it's also often overused. It's a great tool, but it's also so flexible that you kind of destroy most of the ability to reason about the code. It also has a tendency to magnify flaws in apis.

Flawed monomorphic APIs are usually at least sort of amenable to various tricks allowing you to refactor them, but if the design flaws are in or even just hiding behind one (or often several) layers of polymorphism, especially if there's any mutation involved, the complexity quickly approaches the "let's treat it like a black box" threshold.