Polymorphism

In computer science, polymorphism means allowing a single definition to be used with different types of data. It can be a polymorphic language, function or a polymorphic type, and when the domain is restricted to object oriented programming it mainly seems to be the notion on polymorphic functions that is the main concern.

A polymorphic functions is a function where values / parameters takes different data types as input
Polymorphism comes in different forms, often referred to as Universal and Ad hoc, and these are again commonly divided into two groups each.

Polymorphism

This grouping and definition by Cardelli and Wegner [1] states Universal Polymorphism as functions that work on a infinite number of types. Whereas ad hoc polymorphism is functions that work on a finite set of types.

Overloading is the definitions of multiple functions with the same name taking different types, and where each functions for any type must be explicit implemented.

Coercion is the concept of functions inadvertently becoming polymorphic, fx by typecasting!

Inclusion is when an object can be viewed as belonging to many different classes that need not be disjoint; that is, there may be inclusion of classes. Which means that classes share and hide complexity by inheriting or extending common functions.

Parametric polymorphism is also referred to as generics or instances with type parameters. Generics have a single abstraction for multiple data types and can be characterized by reuse by parameterization

Other groups or interesting terms is dynamic-, signature-, inheritance-bound-, static- (runtime) and compile time polymorphism.

Polymorphism can be achieved in different way and have different implementations where the most concern is about run time and compiler efficiency. There are two methods to achieve this; dynamic binding or static binding, where the first have great impact on memory and efficiency and the second have great impact on usability.


[1] L. Cardelli and P. Wegner, "On understanding types, data abstraction, and polymorphism," Computing Surveys, Vol. 17, No. 4, December 1985, pp. 471-522.

[2 ] Dipl.-Inf. Krzysztof Czarnecki, Generative Programming - Principles and Techniques of Software Engineering Based on Automated Configuration and Fragment-Based Component Models Technical University of Ilmenau October 1998, http://www.prakinf.tu-ilmenau.de/~czarn/diss/diss.pdf

[3] Thierry G´eraud and Alexandre Duret-Lutz, Generic Programming Redesign of Patterns http://hillside.net/europlop/HillsideEurope/Papers/GenericProgrammingRedesignOfPatterns.pdf

[4] Jaakko Järvi, Jeremiah Willcock, and Andrew Lumsdaine, Concept-Controlled Polymorphism, Open Systems Laboratory, Indiana University, Bloomington, IN 47405 USA http://www.old.netobjectdays.org/pdf/03/papers/gpce/28300228.pdf