"Polymorphism is not the same as method overloading or method overriding. ... Neither ... are by themselves implementations of polymorphism".
This is a quote from wikipedia
However in the book "Object-Oriented Programming" Timothy Budd states there are "four different forms of polymorphism":
overloading (ad hoc polymorphism)
overriding (inclusion polymorphism)
polymorphic variable (assignment polymorphism)
generics
Who is right? Thanks
Method Overriding is a Run time polymorphism. In method overriding, the derived class provides the specific implementation of the method that is already provided by the base class or parent class.
overriding is where you change the behavior of the base class via a function with the same name in a subclass. So Polymorphism is related to overriding but not really overloading.
-Overloading is when you take an existing method and essentially define it again, but using different parameters which Java sees as a completely different method. -Polymorphism is when you extend the base functionality of a superclass.
Function Overriding in C++ It redefines a function of the base class inside the derived class, which overrides the base class function. Function overriding is an implementation of the run-time polymorphism. So, it overrides the function at the run-time of the program.
Polymorphism is a characteristic or feature of programming languages. Programming languages either support it or they don’t. Since programming languages fall under the umbrella of sometimes substantially different paradigms, different paradigms (functional programming or object oriented programming) may have slightly different interpretations and applications of HOW polymorphism is expressed in that particular paradigm.
As far as I know, in OOP polymorphism is considered one of the basic principles and a very distinctive one. Most of the object oriented languages have polymorphism among its many features. In a nutshell, polymorphism is best seen when the caller of an object with polymorphic implementation is not aware of the exact type the object is. Is is often a consequence of inheritance and casting, is also called subtype polymorphism, and works through the use of vTables.
I share the idea (along with many authors) that operator overload is a manifestation of polymorphism. So if you overload the == operator to take TypeA == TypeB, you are effectively interpreting TypeB as a TypeA if you are comparing elements in a list containing random elements of types A or B, you don't really care what comes in, since they can all be treated for equality. Like many other debates this one has defenders and haters.
But that's the end of the story for OOP.
In functional (declarative) languages (Lisp, F#) since the first class citizens are functions (vs Objects) polymorphism is expressed through relationships between functions and is manifested a bit differently. See Type Polymorphism
The last word I want to put out there is that I love Wikipedia as much as the rest, but you must always take articles with a grain of salt and never trust them blindly without confirming other sources. If you want to get the truth about the true principles of OOP, you should start here:
Object-Oriented Software Construction (Bertrand Meyer)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With