Polymorphism: One Call, Many Behaviors

When the desk checks what kind of vehicle it has before it can price it, every new vehicle means another check, and a forgotten one prices it at $0; polymorphism moves each price into its own class, so one call, rental.price(hours), does the right thing for a bike, an e-bike and a scooter.

By

Updated

Cheat sheet: Polymorphism: One Call, Many Behaviors
Category
Data Structures
Level
Apprentice
Tags
c-sharp, Dynamic Dispatch, java, JavaScript, OOP, Polymorphism, python, typescript