...

/

Duck Typing and Polymorphism

Duck Typing and Polymorphism

Learn what is polymorphism and duck typing in Ruby language.

What is polymorphism

There are some intricate definitions in object-oriented programming. However, not all programmers know what polymorphism and duck typing are, or what the difference is between the two. It happens because programming practice is often easier than theory.

The term polymorphism comes from the Greek roots poly, meaning “many”, and morphe, meaning “form”.

According to Wiktionary, polymorphism is “The ability to assume different forms or shapes” while biologically it means, “The coexistence, in the same locality, of two or more distinct forms… not connected by intermediate gradations”.That’s rather interesting, because we can see “distinct coexistence” and “not connected” simultaneously in polymorphism

The following joke can illustrate polymorphism:

Father: Son, go and get Red Label. Son: 750ml or 1 liter? Mother: Son, go and get Red Label. Son: ...