Inheritance
ELI5 — The Vibe Check
Inheritance lets a class take on all the properties and behaviors of another class. It's like a child inheriting traits from a parent — you get everything for free and can add your own stuff on top. But just like in real life, too much inheritance gets complicated fast.
Real Talk
Inheritance is an OOP mechanism where a subclass acquires the properties and methods of a superclass. It enables code reuse and 'is-a' relationships. Deep inheritance hierarchies are generally discouraged in favor of composition. The Liskov Substitution Principle governs correct inheritance use.
Show Me The Code
class Animal {
speak() { return 'some noise'; }
}
class Dog extends Animal {
speak() { return 'woof'; } // override
}
When You'll Hear This
"Dog inherits from Animal." / "Prefer composition over inheritance for flexibility."
Related Terms
Abstraction
Abstraction is hiding the messy details and showing only what matters.
Composition
Composition means building complex things by combining simple ones, rather than inheriting from a parent class.
Liskov Substitution
Liskov Substitution says if class B extends class A, you should be able to swap B in everywhere A is used without anything breaking.
Polymorphism
Polymorphism means the same method call can do different things depending on which object it's called on. Call 'speak()' on a Dog and you get a bark.