Polymorphism (computer science)

[1] In object-oriented programming, polymorphism is the provision of one interface to entities of different data types.

[2] The concept is borrowed from a principle in biology where an organism or species can have many different forms or stages.

In a 1985 paper, Peter Wegner and Luca Cardelli introduced the term inclusion polymorphism to model subtypes and inheritance,[1] citing Simula as the first programming language to implement it.

Christopher Strachey chose the term ad hoc polymorphism to refer to polymorphic functions that can be applied to arguments of different types, but that behave differently depending on the type of the argument to which they are applied (also known as function overloading or operator overloading).

[5] The term "ad hoc" in this context is not pejorative: instead, it means that this form of polymorphism is not a fundamental feature of the type system.

[7] Parametric polymorphism is a way to make a language more expressive while still maintaining full static type safety.

Some, however, such as Common Lisp Object System, provide multiple dispatch, under which method calls are polymorphic in all arguments.

The interaction between parametric polymorphism and subtyping leads to the concepts of variance and bounded quantification.

Static polymorphism executes faster, because there is no dynamic dispatch overhead, but requires additional compiler support.

As a result, more code can be shared for a reduced system size at the cost of runtime overhead.