Polymorphism
m (Reverted edits by Ebybymic (Talk); changed back to last version by Matthew Harward) |
|||
Line 1: | Line 1: | ||
− | + | [[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]] | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− |
Latest revision as of 03:23, 25 November 2010
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.
Nomenclature | |
---|---|
Techniques: Abstraction | Aggregation versus Composition | Association versus Dependency | Coupling | Encapsulation | Information hiding | Inheritance | Multiple Inheritance | Overloading | Polymorphism
Features: Abstract class | Class versus Object | Component versus Module | Instance | Interface | Method | Package versus Namespace | Superclass | Subclass |