A coding technique where the same named function, operator, or object behaves differently depending on outside input or influences. Usually implemented as parameter overloading where the same named function is overloaded with other versions that are called either with a different type or number of parameters. Polymorphism is a general coding technique and other specific implementations are common such as inheritance, operator overloading, and interfaces.
The word polymorphism means "many forms". In computer programming, we sometimes expand that simple memory aid as "one name, many forms". More formally, polymorphism is the capability of the same command to be interpreted differently when used with or received by different objects (a single command that works with many objects) and is frequently associated with Object Oriented Programming (OOP).
Parametric Polymorphism: Overloading
The ability of a method to act differently depending on the type or number of parameters passed in (a.k.a. Overloading).
Inheritance-Based Polymorphism
A.k.a. Overriding, Inclusion Polymorphism, Runtime Polymorphism, Dynamic Binding, or Late Binding
Inheritance is a coding element which involves defining methods in a parent class and overriding them with new implementations in child classes. For example, you could define a method in a parent class and override it in descendant classes as needed. When using an object instantiated from one of these classes, you don't actually need to know which method implimentation is used, you just need to know the name of the method or property to use.
Polymorphism allows the software architect to design a dog.run and a cat.run method and then the programmer can decide at development time whether to instantiate a dog or cat object and either way he knows to call the run method to make the object run. If the designer created a MakeDogRun and a MakeCatRun methods, then the programmer would have a hard time remembering different commands and could not easily substitute one for the other (see substitutability below).
Interface-Based Polymorphism
An interface promises to support the same behavior across multiple classes without the baggage of a particular implementation. You can design classes in different descendant lines with common methods and properties without an interface but an interface ensures you implement the methods and properties using the same names and parameters (a common interface).
For example, you may wish to implement an IError interface that specifies a common error tracking interface you will use with all classes you want to log errors. One of your specified methods might be a LogError(pString) function that is required for all classes that implement the IError interface. The LogError method might record a log entry dependant on the class. Perhaps either extra class specific information or perhaps some classes will log errors to a generic log table and others will log to a different destination log table.
(Substitutability)
A.k.a. Subtyping Polymorphism, or Inclusion Polymorphism
Substitutability allows a descendant class to be used anywhere an associated parent class is used. In object oriented programming a variable could refer to one object at one time and then another object another time. This allows the designer of software to create both a dog.run and a cat.run methods and then decide at runtime whether the variable will be a dog or a cat.