richard pickworth wrote:
Can anyone explain polymorphism?(very simply).
According to The American Heritage Dictionary of the English Language
http://www.bartleby.com/61/
polymorphism
SYLLABICATION: pol·y·mor·phism
PRONUNCIATION: pl-môrfzm
NOUN: 1. Biology The occurrence of different forms, stages,
or types in individual organisms or in organisms of the same
species, independent of sexual variations. 2. Chemistry
Crystallization of a compound in at least two distinct forms.
Also called pleomorphism.
OTHER FORMS: poly·morphic, poly·morphous —ADJECTIVE
poly·morphous·ly —ADVERB
According to Wikipedia
In computer science, polymorphism is the idea
of allowing the same code to be used with different types,
resulting in more general and abstract implementations.
The concept of polymorphism applies to functions
as well as types. A function that can evaluate to
and be applied to values of different types
is known as a polymorphic function.
A datatype that contains elements of an unspecified type
is known as a polymorphic datatype.
There are two fundamentally different kinds of polymorphism.
If the range of actual types that can be used is finite and
the combinations must be specified individually prior to use,
it is called ad-hoc polymorphism. If all code is written
without mention of any specific type
and thus can be used transparently with any number of new types,
it is called parametric polymorphism.
Programming using the latter kind is called generic programming,
particularly in the object-oriented community. However,
in many statically typed functional programming languages
the notion of parametric polymorphism is so deeply ingrained
that most programmers simply take it for granted.
Polymorphism gained most of its momentum
when object-oriented programming became a buzzword.
Polymorph literally means many form[s].
Lots of things in C++ can be described as polymorphs or polymorphisms
including function and operator overloading, inheritance and templates
but, usually, when C++ programmers use the term polymorphism,
they mean run-time polymorphism, late binding and dynamic dispatch --
virtual functions which may be overridden in derived types.
This is, of course sloppy [ab]use of the English language.
The term is much to vague and general to communicate useful information.
I try to avoid using this word whenever possible.
If you decide to use it, please elaborate a little when you first use it
and explain exactly what it means to *you*.