Polymorphism
ELI5 — The Vibe Check
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. Call it on a Cat and you get a meow. Same interface, different behavior. It's shape-shifting for code.
Real Talk
Polymorphism allows objects of different types to be treated uniformly through a shared interface. Runtime polymorphism (dynamic dispatch) selects the correct method implementation at runtime. Enables writing generic code that works with any conforming type without knowing the specific implementation.
Show Me The Code
const animals: Animal[] = [new Dog(), new Cat(), new Bird()];
animals.forEach(a => console.log(a.speak()));
// 'woof', 'meow', 'tweet'
When You'll Hear This
"Polymorphism lets us add new animal types without changing the loop." / "That's the power of polymorphism — same interface, different behaviors."
Related Terms
Abstraction
Abstraction is hiding the messy details and showing only what matters.
Inheritance
Inheritance lets a class take on all the properties and behaviors of another class.
Open-Closed
Open-Closed means your code should be open for adding new features but closed for editing old working code.
Strategy Pattern
You're writing a sorter and want to sort by price, name, or date depending on user choice.