Polymorphism

Domain: Design Principles

🎯 Motivation

Polymorphism lets different types respond to the same method call in their own way. This lets you write generic code that works with any compatible type, reducing duplication.

πŸ“‹ Concrete Example

A speak() method on Dog returns β€œwoof” and on Cat returns β€œmeow”. A loop calling animal.speak() over a list works for any animal subclass without conditionals.

πŸ”— Analogy

A universal remote has a β€œplay” button that works on any TV brand. The remote does not care if it is Sony or Samsung β€” each TV knows how to respond to β€œplay”.