What Is Polymorphism
Polymorphism is one of the features of Object Oriented Programmings or OOPS. The word polymorphism is derived from a Greek word which denotes the existence of species having multiple forms. The process of Polymorphism allows a programmer to share an entity to serve two or more motives. Since its inception polymorphism has become a fundamental feature of OOPS and every amateur programmer is taught its basic.
Polymorphism in computer programming
OOPS was cracked in 1950s by a group of researchers at MIT. However, in the late 1970s the popularity of C++ programming language showcased the use of polymorphism. Later, OOPS became the main paradigm for bigger programming languages and the polymorphism became one of the most intriguing features of computer programming.
Polymorphism performs a chief task of OOPS which is known as message passing among different objects of different or same classes. Usually, objects of different classes share a public interface which performs certain operations or activities. Polymorphism is usually performed using objects where a certain type of objects applies an interface which is present in other type and vice versa.
How polymorphism in implemented?
Basic implementation of polymorphism in C++ is done via a phenomenon known as operator overloading. In this phenomenon, the theory of polymorphism is applied on basic C++ operators such as ‘+’, ‘.’, ‘-‘, ‘/’, ‘*’ etc. These arithmetic operators are loaded with two or three features via a function. The most common use of operator overloading is done on ‘+’ operator, where it is used to add integers or float data types, concatenate two strings, and to join or attach two link lists, all in one program. This type of polymorphism is not often used in industry but frequently used in programming courses. This type of polymorphism is known as compile time polymorphism.
However, operator overloading and overriding are not regarded as pure implementation of polymorphism. This was a big debate in the early 90s.
Other type of polymorphism is known as run time polymorphism, which is implemented on methods or functions. A functions or routines are defined two or more times and carry out specific task depending on the function call and which object calls it. Every function accepts parameters and the function produces different outputs depending on its parameters. This type of polymorphism is known as run time polymorphism and its used in Industry.
Late binding and Early binding
Binding here denotes the transfer of message during the life span of an active program. Early binding means passing of message during compiling of a program. Late binding is known as the passing of message during run time. Late binding is also known as dynamic binding.