Sunday, December 30, 2012

Polymorphism in OOP

Polymorphism in OOP is the ability of objects belonging to different types to respond to method, filed, or property calls of the same name. The caller doesn't have to know the type of the callee so that the exact behavior is determined at run-time.

For strong type languages, polymorphism usually means that type A derives from type B or C, In weakly typed languages types are implicitly polymorphic: duck typing allows polymorphism without inheritance.

There are some disputes whether overloading and overriding is a part of polymorphism.
  • Wikipedia explains they are not the same. (Polymorphism is not the same as method overloading or method overriding.1 Polymorphism is only concerned with the application of specific implementations to an interface or a more generic base class.)
  • Some of OOP books explain "method overloading" as an example of polymorphism.
  • This paper explains overloading as a part of polymorphism
  • This post explains that overriding is a part of polymorphism, whereas overloading is not.

Generic programming is also known as "parametric polymorphism".


  1. Polymorphism in object-oriented programming
  2. OBJECT.__class__ is CLASS and "isinstance(OBJECT, CLASS)" for polymorphism in python
  3. Duck typing
  4. Function overloading
  5. Method Overriding
  6. Is Method Overloading considered polymorphism?
  7. Polymorphism vs Overriding vs Overloading

No comments:

Post a Comment