Principles
Polymorphism: Subclasses Instead of a Type Field
Polymorphism lets a caller ask every object the same question while each subclass answers it its own way. These lessons take a car rental class that switches on a type string in every method, give each kind of car its own subclass, and then add vans as one new class.
Pick your language
When to use it
Use it when
Two or more methods switch on the same type field.
Skip it when
An object changes kind while it lives, like a rental upgraded mid-trip. It can't change class, so use State or Strategy.
Spot it by
The same switch or if chain on one field, repeated in several methods.