Click here to Skip to main content
15,905,967 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Is the only use of polymorphism is to use the same name of the base class method for the derived method?
Posted
Comments
Sergey Alexandrovich Kryukov 20-Jan-15 13:33pm    
No. Not only this is no "the only use", what you mention is not the use of polymorphism at all.
—SA

Hi,

No. Polymorphism is a really powerful feature of OOP and enables you to:
1. Override methods in derived classes and call the overridden version from the base class if a reference to the derived one is stored in a base class variable.
2. Exchange between child types (I.E. you can pass to a function which, for instance, needs a real number, an integer number or a rational one, or an irrational one). This because RationalNumber inherits from RealNumber.
3. Making conversions between types (this includes in part the point 2).

In order to understand it better, I advice you to read the serie of articles written by Akhil Mittal published here on CodeProject: Diving in OOP (Day 1) : Polymorphism and Inheritance (Early Binding/Compile Time Polymorphism) [^]. Otherwise I had to write here an article about that or explain it really synthetically (and I do not want to do it as this is a really huge and important topic)

Also read on Wikipedia http://en.wikipedia.org/wiki/Polymorphism_%28computer_science%29[^]

Hope this helps...

Jymmy097
 
Share this answer
 
Please see the my comment to the question. The polymorphism is not what you think at all. This is having some set of objects of different runtime types which can be manipulated based on the same interface. With .NET, such interface could be common base class, or some interface type (unfortunately, less known fact, about an interface type).

This is not directly related to "names" of members. The members of common interfaces are uses in a polymorphic way not because the names are the same, but because the members themselves are the same. Can you see the difference? The members are accessed using one or another mechanism of dynamic dispatch: http://en.wikipedia.org/wiki/Dynamic_dispatch[^].

See also: http://en.wikipedia.org/wiki/Polymorphism_%28computer_science%29[^].
See also my past answer:
POLYMORPHISM WITHOUT OVERLOADING AND OVERRRIDING IS POSSIBLE[^],
Interfaces and Polymorphism[^].

—SA
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900