+ 1
Polymorphism
who can help me understand polymorphism ?
6 Respostas
+ 10
Avinesh Oh wow... After reviewing many of the really bad answers in those posts, I can understand why people are so confused about polymorphism. This is a case where community answers may not be the best source.
Many of the answers are terrible or wrong. Some answers are decent but only scratch the surface or take a hard left turn from good to bad.
I will say that the best of those posts shared are the collective answers posted in the last link.
https://www.sololearn.com/Discuss/149024/?ref=app
I especially liked the answer posted by @Simon Lepasteur
----
"Usually, when we speak about polymorphism in c++, we don't mean function overloading or generic programming, we mean polymorphism via subtyping.
Therefore it is the possibility of a method of an object to have different behaviour depending on the "real" type of the object."
----
This is especially true in strongly typed languages like C# and Java where interfaces are highly used to decouple dependencies from concrete references.
+ 5
David Carroll 👏👏👏👏👏superb
+ 1
Please use the search bar.
https://www.sololearn.com/discuss/138514/?ref=app
https://www.sololearn.com/discuss/93008/?ref=app
https://www.sololearn.com/discuss/1814623/?ref=app
https://www.sololearn.com/discuss/830886/?ref=app
https://www.sololearn.com/discuss/317841/?ref=app
https://www.sololearn.com/discuss/795132/?ref=app
https://www.sololearn.com/discuss/149024/?ref=app
+ 1
David Carroll polymorphism via subtyping is just one of the many forms of polymorphism. Polymorphism is a polymorphic concept.(😂) and I think method overloading is a form of polymorphism.
Yvon Richel Désir Bemba
In general, polymorphism means "many forms". It is the ability for an object, method, parameter etc to have many forms.
Some animals are domestic, some are wild. Some are herbivores, some are carnivores. Some are even both. Animal is a polymorphic type. A dog is a polymorphic object. It is both an animal and a carnivore.
All animals reproduce but they do so differently. Therefore Animal.reproduce is a polymorphic method.
It is that simple but there is more to polymorphism in OOP. There are interfaces, inheritance and other concepts that aid polymorphism.