Jump to content

Talk:Polymorphism in object-oriented programming

Page contents not supported in other languages.
From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Tiburondude (talk | contribs) at 21:19, 11 April 2009 (Reply). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

Older comments

I would say that being able to respond to method calls by their names is only a consequence of polymorphism, and is caused by the methods being virtual. Polymorphism is the ability of treating objects of classes also as objects of all their superclasses, in all aspects (thus being able to use their members such as methods). —Preceding unsigned comment added by Balrog-kun (talkcontribs) 29 March 2006

Actually, it's the other way around. What you're describing is called inheritance, and polymorphism is a consequence of inheritance. All systems using inheritance are polymorphic, but not all polymorphic systems use inheritance (in Smalltalk you can use inheritance, but it's not necessary), or even have the concept of "class" (like Self or Javascript which are based on prototypes instead of classes).--Cynebeald (talk) 17:44, 23 January 2008 (UTC)[reply]

polymorphism manupulates data.

Is it true that one can program the system to jump over clssses i.e., I want some data but not all from each class, cub class, partial class, and supr class however, I do not want to have to search each class thereby slowin g down my processing power or taking up more processor power therteby slowing down my time to transmit. I want to <Get> data fro the Class and the supper class by settin g pointrs skipping the sub and partial clases using if then statem e In nts. If this x in class skip to super c;ss and <get> data and <send>. This is imperative for keeping real time systems.

Thoughts,

Mike

Mike_Benso@yahoo.com

—Preceding unsigned comment added by 69.136.233.19 (talk) 11 December 2006

short description

polymorphism as such has nothing to do with inheritance. Polymorphism means than objects that implement the same method name can be exchanged. The definition given seems to stem from static typing. —Preceding unsigned comment added by 89.62.63.186 (talk) 13 February 2007

#include <vector>

is the #include <vector> even necessary? Maybe I didn't read it well enough, but it seems an array is being used not a vector - CKL —Preceding unsigned comment added by 71.210.245.151 (talk) 3 July 2007

VB.NET Example

Why is this using interfaces rather than inheritance which all the other OO examples use? This make the examples inconsisteny in what they are actually doing. Surely it would be better for consistency to show the inherited example with the interface one as an extenison of this. —Preceding unsigned comment added by 81.133.167.102 (talk) 16:42, 14 December 2007 (UTC)[reply]

I agree, inheritance would be the more natural way to do this. 83.166.176.136 (talk) 14:07, 9 July 2008 (UTC)[reply]
In addition, the article implies below the VB example that it's a deficiency in Java that leads to requiring an abstract class rather than the use of an abstract class being the correct semantics. Could someone with the required knowledge please edit the VB example so we can get rid of this misleading comment while maintaining sense? Morticed (talk) 11:21, 1 August 2008 (UTC)[reply]

Java Example

The Java example is dealing with Shapes, while all the other examples are dealing with Animals. —Preceding unsigned comment added by 199.26.230.102 (talk) 16:04, 20 December 2007 (UTC)[reply]

I converted the C++ version to Java and added it to the article in place of the Shapes example. I forgot to log in, though, so it shows up as my IP. --Powerlord (talk) 06:19, 26 February 2008 (UTC)[reply]

Java Section

This is just the concept of Inheritance and does not show polymorphism? Please email your response to siu02rk@hotmail.com

Thanks

90.211.234.107 (talk) 10:08, 19 May 2008 (UTC)[reply]

syntax of the examples

JAVA language example:
protected Animal(String name) { this.name = name; }


this particular line of code does not give correctness, this method needs a return type. so what is it?
Xmlv (talk) 21:08, 20 November 2008 (UTC)[reply]


C# language example:
Using VS 2008 Express the example does not compile giving an error:

 Error	1	'AnimalBase.AnimalBase(string)' is inaccessible due to its protection level 
 Program.cs	40	9	Animal

I am thinking AnimalBase is getting protected from the line: private string _name; to fix I added the word public in front of AnimalBase: public AnimalBase(string name)

Note on 4/11/09 from original author: I think protected is best for the constructor, Name has to be public to satisfy the interface, but the class should be marked abstract. I made those changes. The rationale is that the design of the Animal Base class is to function as purely a base class. It cannot be instantiated, only inherited from. —Preceding unsigned comment added by Tiburondude (talkcontribs) 21:18, 11 April 2009 (UTC)[reply]

Overloading is not Polymorphism

I understand that polymorphism is completely different from overloading, therefor, I think the comments relating both concepts should be removed from the article. Ramiro Pereira de Magalhães (talk) 14:27, 11 January 2009 (UTC)[reply]

C# code commentary

Under the C# code it says "This is a slightly modified implementation of the Strategy pattern". Well I don't think so. I'd say it's the most regular use of inheritance. Just having the subclass instances in a List doesn't make it "Strategy".

Reply

Sorry if this is written unclearly. Appreciate the editing help. The intention is to say that since the strategy pattern usually has read/write properties of type interface, and the example has a read only property of type interface with the only way to set the "strategy" interface is via the constructor. That's what I mean by slightly modified implementation of the strategy pattern. Having a generic list of interfaces is completely unrelated to the strategy pattern. Thanks! —Preceding unsigned comment added by 76.126.198.46 (talk) 20:55, 11 April 2009 (UTC)[reply]