Member-only story

Why Inheritance in Programming Can Be a Bad Idea

Nnaemezue Obi-Eyisi
4 min readFeb 4, 2025

--

Inheritance is one of the fundamental concepts of Object-Oriented Programming (OOP). At first glance, it seems like a great way to promote code reuse and establish relationships between classes. After all, what could be more logical than having a Car class inherit from a Vehicle class, or a Dog class inherit from an Animal class?

But here’s the problem: inheritance often introduces more complexity and long-term pain than it solves. If you’ve ever struggled with deep class hierarchies, rigid dependencies, or unexpected bugs due to overridden methods, you’ve already experienced the downsides of inheritance firsthand.

Let’s break down why inheritance can be problematic and explore better alternatives.

1. Tight Coupling: Your Code Becomes a House of Cards

Inheritance creates a strong dependency between parent and child classes. If you modify the parent class, all child classes are affected — sometimes in ways you didn’t anticipate. This makes your code fragile and harder to maintain.

Imagine you have a Bird class with a fly() method. Later, you introduce a Penguin class that inherits from Bird, but penguins can’t fly. You now have to override or disable fly(), which indicates a flaw in the original design. This is known as the…

--

--

Nnaemezue Obi-Eyisi
Nnaemezue Obi-Eyisi

Written by Nnaemezue Obi-Eyisi

I am passionate about empowering, educating, and encouraging individuals pursuing a career in data engineering. Currently a Senior Data Engineer at Capgemini

No responses yet