3.5 Polymorphism
Polymorphism is a showy name describing a simple concept: different behaviors happen depending on which subclass is being used, without having to explicitly know what the subclass actually is. It is characterized by the Liskov Substitution Principle. The design principle reminds us we should be able to substitute any subclass for its superclass.
As an example, imagine a program that plays audio files. A media player might need to load an AudioFile object and then play it. We can put a play() method on the object, which is responsible for decompressing or extracting the audio and routing it to the sound card and speakers. The act of playing an AudioFile object could feasibly be as simple as this:
from pathlib import Path
audio_file = SomePlayer(Path("/path/to/file"))
audio_file.play()
However, the process of decompressing and extracting an audio file is very different for different types of files. While .wav files are stored...