Today we’ll talk about Polymorphism: poly = many, morph = shape or form, so it’s basically manyformism. Now that we’ve taken the obligatory and unhelpful direct translation of terms, let’s dig in.
The same operations can be executed in many different things, maintaining the concept, although not the details of the operation. Peeling a banana shares the concept with peeling a tangerine, but not the same mechanics. That’s polymorphism, and there are particular ways to express it in different programming languages.
In java, the main way to implement polymorphism is through the overriding of previously declared behaviors.
In the class or interface-based relationship, some blueprint stated that a particular action could be executed, and elsewhere the behavior is specified either for the first time (when implementing interfaces or extending abstract classes), or assertively by overriding the behavior previously declared.
So, a “skinned fruit” is “peelable” (declared action), but the way it’s “peeled” differs from fruit to fruit (implemented).
In another scenario, a “generic-cap”-capped bottle can be opened by removing the cap (defined behavior), but then there are “screw cap”-capped bottles plastic, and “non-screw steel cap”-capped crystal bottles, which may have different behavior.
The generic-cap is similar to the non-screw steel cap, and they are removed the same way (using a bottle opener); but the screw cap needs to be turned – so the behavior is overriden for the latter, although it’s maintained for the former.
Practical examples for these can be found here: https://docs.oracle.com/javase/tutorial/java/IandI/polymorphism.html
By the way, that’s just the way Java does it, which is fitting due to the nature of this series; there are more ways to implement polymorphism, and that may be the topic of a future article.