🍏 Polúsmorphḗ (Polymorphism)

Maksim Ryzhikov
2 min readFeb 22, 2021

--

What is polymorphism. Diversity(polús) of forms(morphḗ)?

Apple could be “Glory to the Winners” or “Grushovka Moskovskaya” does it matter for apple pie? I guess yes, when we talk about the final result. The taste of these two sorts is different. We can have a recipe for “Glory to the Winners” apple pie or recipe “Grushovka Moskovskaya” apple pie. But if we compare those recipes we would see that they more similar than different. Can we say that for the recipe of “Apple” pie it doesn’t matter what kind of apple do you take? I think yes, because the difference between two types of apples is not so important for the recipe. We can go further and say that we can create one recipe for apple pie! Do we need it? What is wrong to have N recipes for apple pie? I don’t know. Looks like it’s even better to have different recipes for different apples. You can easily find a needed recipe by apple kind. But wait, what if we get a new apple kind from which we should make apple pie. We don’t have a recipe for it yet. We can go by ad hock way and just take a recipe for another apple kind and cook. Or by the right way by writing a recipe for the new apple kind. It doesn’t sound efficiently to write N times mostly the same algorithm of cooking apple pie. Wait! But what if we found inaccuracy or mistake in this algorithm?! Oh…. It’s better to fix it in every written recipes. Looks discourage. Maybe we throw all our work and start from scratch and at this time make it definitely ideally with new technologies and approaches. Now we would have only one recipe for apple pie!

We can write the mathematical formula of greet abstract apple pie:

Apple pie = Apple + “Apple” recipe

now we can use the same recipe for any kinds of apple

“Grushovka Moskovskaya” Apple pie = “Grushovka Moskovskaya” + “Apple” recipe

here we assume that “Apple” in our recipe is “Grushovka Moskovskaya”. Or we can create “Glory to the Winners” apple pie if we want

“Glory to the Winners” Apple pie = “Glory to the Winners” + “Apple” recipe

and now “Apple” in our recipe is “Glory to the Winners”. “Apple” in our recipe is not a concrete apple. It looks like a placeholder for specific kinds/shapes of apple. Can we say that our “Apple” recipe is polymorphic? It definitely may have different taste depends on apple kind

--

--

No responses yet