Click here to Skip to main content
15,888,286 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I have recently understood the concept of Polymorphism in OOP. So, I defined it in my own words but wanted to ask that "Is it correct". We all know that no definition can be absolutely correct.

Polymorphism can be defined as "Common Interface among instances of classes but traits for each instance can vary keeping the interface same".

:)
Posted
Updated 15-Dec-14 9:26am
v2
Comments
Maciej Los 15-Dec-14 15:18pm    
What's an issue?
Shaharyaar 15-Dec-14 15:32pm    
I have read different type of definitions regarding polymorphism. Someone defined it as "Ability of Object to respond to the same message with different answers".
While some say that "Methods or interface is building block in concept of Polymorphism". So, should I go to the responding of Objects or to the Interface?
Sergey Alexandrovich Kryukov 16-Dec-14 1:43am    
You are trying to replace understanding with words. It's useless.
—SA
Tomas Takac 15-Dec-14 15:23pm    
Good for you. I still remember my first time with polymorphism. Those were the days...
PIEBALDconsult 15-Dec-14 15:38pm    
Please don't.

1 solution

The concept - more to say theory - of polymorphism[^] in CS is well defined (including OOP) and there is not much to debate about. The differences may come from different level/type of implementation in different languages...
Your phrase shows me that you only take in count virtual methods - that's only one kind of polymorphism...
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 16-Dec-14 1:54am    
Your statement "not much to debate" is very questionable. You would be surprised, but when I looked at the Wikipedia article you referenced, I found that it was completely re-written, compared to the last time I looked at it; and at that time, this article was complete gibberish. Good riddance. So far, I can see some idiotic explanations of polymorphism involving mythical "compile-time polymorphism", something you can also see in some CodeProject answers.

I don't know what do you mean my "other kinds" of polymorphism, but polymorphism based on interfaces fundamentally differs from the polymorphism based on virtual methods, due to multiple inheritance of interfaces and (in .NET) the ability to implement interfaces in value types (struct). Also we can discuss polymorphism based on messages (like in Smalltalk). I would also considered polymorphism based on scripting: the name of the method is resolved at the call, so it creates similar effect...

So, there is enough to debate. With the OP's question the situation is different: it looks like OP goes in anti-scientific way: trying to play with words instead of understanding.

—SA
Kornfeld Eliyahu Peter 16-Dec-14 2:02am    
By "other kinds" I mean, inheritance, method override and so - as I understood the sentence of OP he focused only on virtual methods...
"debate" - I mean that the fundamentals are clear (or should be for anyone who had CS 101) and the Wikipedia article lay them out in a good manner (I didn't know of previous versions and picked the article after reading it). I do not refer to wrong answers - for me it is no debate, but wrong answer only...
On the other hand I would like some debate about how to extend OOP (and programming languages of non OOP too) with other kinds of polymorphism...
Sergey Alexandrovich Kryukov 16-Dec-14 2:42am    
I understand that you did not refer to anything wrong. I just say that this change is indicative. It's a "philosophical" question, if it is debatable or not, the question is: debatable among who... :-)

Anyway, you did not name more than one kind of polymorphism. Inheritance and override cannot be considered as something different and independent; they are not equal components: inheritance is one of the prerequisites to override...

—SA
Kornfeld Eliyahu Peter 16-Dec-14 2:55am    
I meant method overLOAD of course...
Sergey Alexandrovich Kryukov 16-Dec-14 3:01am    
And "overload" are not related to polymorphism at all. However, it is related to one of the myths of polymorphism. Functionally, "overloading" is nothing, this is a purely syntactic thing which does not effect any behaviors whatsoever. Bad term, actually: nothing is "overloaded", because nothing is "loaded".
—SA

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