Definition of Polymorphism in Computers
One of the core capabilities of object-oriented programming languages is polymorphism. Polymorphism is the ability for an object to be used differently or considered a different type of object depending on the context in which it is used.
-
Object-oriented Programming
-
Object-oriented programming is a programming paradigm that uses encapsulated entities known as "objects." Objects are groupings of attributes and functions that define a component of the program. For example, a "car" object would have the attributes defining its color, model and brand, and would include functions such as "drive" or "refuel."
Inheritance
-
Object-oriented programming languages give objects the ability to inherit from other objects, making the new object a subset of its parent. For example, a "square" object could inherit from a "shape" object. The "square" object would then have the attributes and functions defined within the "shape" object, as well as any it defined itself.
-
Polymorphism
-
Polymorphism allows objects to be treated differently depending on the context in which they are used. For example, with polymorphism, if a line of code uses a "shape" object, it could also use any objects that inherit from the "shape" object, such as a "square" or "circle" object.
-
References
- Photo Credit computer image by Hao Wang from Fotolia.com