Content deleted Content added
→Static and dynamic polymorphism: Add link to unfamiliar term I had to look up while reading. -- Regards, AFZ (hi from Texas!) Tags: Mobile edit Mobile web edit |
No edit summary |
||
(2 intermediate revisions by 2 users not shown) | |||
Line 2:
{{Distinguish|Polymorphic code}}
{{Polymorphism}}
In [[programming language theory]] and [[type theory]], '''polymorphism''' is the
In [[object-oriented programming]], polymorphism is the provision of one [[Interface (object-oriented programming)|interface]] to entities of different [[data type]]s.<ref>{{cite web |url=http://www.stroustrup.com/glossary.html#Gpolymorphism |last1=Stroustrup |first1=Bjarne |author1-link=Bjarne Stroustrup |title=Bjarne Stroustrup's C++ Glossary |date=February 19, 2007 |quote=polymorphism – providing a single interface to entities of different types.}}</ref> The concept is borrowed from a principle in [[biology]] where an organism or species can have many different forms or stages.<ref name="Moved">{{cite web |title=Polymorphism |work=The Java Tutorials: Learning the Java Language: Interfaces and Inheritance |publisher=Oracle |url=https://docs.oracle.com/javase/tutorial/java/IandI/polymorphism.html |access-date=2021-09-08}}</ref>
Line 19:
===Ad hoc polymorphism===
{{Further|Ad hoc polymorphism}}
[[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]]).<ref name=Strachey00/> 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. In the [[Java (programming language)|Java]] example below, the <code>
<syntaxhighlight lang="java">
Line 109:
static void letsHear(final Pet pet) {
System.out.println(pet.speak());
}
|