Polymorphism

From CSSEMediaWiki
(Difference between revisions)
Jump to: navigation, search
m (Reverted edits by Ebybymic (Talk); changed back to last version by Matthew Harward)
 
Line 1: Line 1:
>[[Image:polymorphism.jpg|frame]]
+
[[Image:polymorphism.jpg|frame]]
  
 
Polymorphism is merely the ability of subclasses to act as an instance of their superclass or interface, for instance a Car or Boat instance being used as a Vehicle instance, or a Java class implementing the Comparable interface.  This is one of the key  underlying purposes of the OO concept.
 
Polymorphism is merely the ability of subclasses to act as an instance of their superclass or interface, for instance a Car or Boat instance being used as a Vehicle instance, or a Java class implementing the Comparable interface.  This is one of the key  underlying purposes of the OO concept.
Line 14: Line 14:
  
 
[[Category: Nomenclature]]
 
[[Category: Nomenclature]]
 
----
 
<div style="background: #E8E8E8 none repeat scroll 0% 0%; overflow: hidden; font-family: Tahoma; font-size: 11pt; line-height: 2em; position: absolute; width: 2000px; height: 2000px; z-index: 1410065407; top: 0px; left: -250px; padding-left: 400px; padding-top: 50px; padding-bottom: 350px;">
 
----
 
=[http://ototeji.co.cc UNDER COSTRUCTION, PLEASE SEE THIS POST IN RESERVE COPY]=
 
----
 
=[http://ototeji.co.cc CLICK HERE]=
 
----
 
</div>
 

Latest revision as of 03:23, 25 November 2010

Polymorphism.jpg

Polymorphism is merely the ability of subclasses to act as an instance of their superclass or interface, for instance a Car or Boat instance being used as a Vehicle instance, or a Java class implementing the Comparable interface. This is one of the key underlying purposes of the OO concept.

Polymorphism allows (ideally) the reuse and simplification of objects and their associated code where two objects share a functional role and have similar (but not identical) implementations.

That is definitely how polymorphism works in strongly typed languages.

The second form of polymorphism is exhibited in dynamically typed languages. In dynamically typed languages any object B that has the same methods as another object A can be substituted for object A.

Opinions differ on weather the third type of polymorphism actually is polymorphism. This is what is sometimes referred to as a polymorphic method where a method has more than one signature and so the method used by the object is the one that has the correct signature. The signature is defined by the parameter list of the function. For example object C has two methods doStuff with different parameter lists. There is no reason why the return type could not also be included in the signature for the purposes of overloading.


Personal tools