Polymorphism

From CSSEMediaWiki
Revision as of 23:44, 25 September 2008 by Jason Clutterbuck (Talk | contribs)
Jump to: navigation, search
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 whats is sometimes referred to as a polymorphic method. this is 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. There is no reason why the return type could not also be included in the signature for the purposes of overloading.

Personal tools