Alexito's World

A world of coding 💻, by Alejandro Martinez

🔗 Linked post

Check out the linked article.

Let's avoid inheritance!

Cool article about inheritance and the no so cool things about it.

Yes, it is a very cool language feature, and it lets you use the word "polymorphic" when talking to your colleagues or boss about it; but from what I have seen so far, there have been more misuses and abuses of inheritance than there have been legitimate and clever uses of it.

I've been in that position and it's not cool to have a hierarchy that is a mess. There are always other ways of doing it, even if sometimes it's hard to see it. Other languages like Go doesn't have subclassing as its feature, and it's totally possible to do cool things with composition. It's the right tool for some occasions, don't let me wrong, but maybe we have to try to not take it as our first option.

So let's try avoid inheritance and see what happens ;)

If you liked this article please consider supporting me