Originally posted by Jade McClooney:
Any clarity on this issue? It seems to be something people don't really agree on.
My view is that overloading isn't polymorphism. The term (polymorphism) is sometimes loosely used, but then there is a problem with what it really means.
Originally posted by Jade McClooney:
Any clarity on this issue? It seems to be something people don't really agree on.
My view is that overloading isn't polymorphism. The term (polymorphism) is sometimes loosely used, but then there is a problem with what it really means.
polymorphism
Generally, the ability to appear in many forms. In object-oriented programming, polymorphism refers to a programming language's ability to process objects differently depending on their data type or class. More specifically, it is the ability to redefine methods for derived classes. For example, given a base class shape, polymorphism enables the programmer to define different circumference methods for any number of derived classes, such as circles, rectangles and triangles. No matter what shape an object is, applying the circumference method to it will return the correct results. Polymorphism is considered to be a requirement of any true object-oriented programming language (OOPL).
The type of polymorphism described above is sometimes called parametric polymorphism to distinguish it from another type of polymorphism called overloading.
Overloading
In programming languages, a feature that allows an object to have different meanings depending on its context. The term is used most often in reference to operators that can behave differently depending on the data type, or class, of the operands. For example, x+y can mean different things depending on whether x and y are simple integers or complex data structures.
Not all programming languages support overloading but it is a feature of most object-oriented languages, including C++ and Java. Overloading is one type of polymorphism.
The number of times this topic has been beaten to death, you'd think it was a cat or something...
Rob
SCJP 1.4
Originally posted by Valentin Crettaz:
Your last sentence doesn't make much sense since overriding is in direct relationship with polymorphism, I guess you meant overloading...
Ok forget it I see that you corrected that
Rob
SCJP 1.4
Originally posted by Erik Dark:
OVERLOADING IS NOT POLYMORPHISM !
In object-oriented programming, polymorphism (from the Greek meaning "having multiple forms") is the characteristic of being able to assign a different meaning or usage to something in different contexts - specifically, to allow an entity such as a variable, a function, or an object to have more than one form. There are several different kinds of polymorphism.
1) A variable with a given name may be allowed to have different forms and the program can determine which form of the variable to use at the time of execution. For example, a variable named USERID may be capable of being either an integer (whole number) or a string of characters (perhaps because the programmer wants to allow a user to enter a user ID as either an employee number - an integer - or with a name - a string of characters). By giving the program a way to distinguish which form is being handled in each case, either kind can be recognized and handled.
2) A named function can also vary depending on the parameters it is given. For example, if given a variable that is an integer, the function chosen would be to seek a match against a list of employee numbers; if the variable were a string, it would seek a match against a list of names. In either case, both functions would be known in the program by the same name. This type of polymorphism is sometimes known as overloading.
Originally posted by Jade McClooney:
I guess there isn't much clarity after all. Its probably just one of those things that are there for people to debate over. Wasn't it fun? (haha)...
No hard facts here, but who cares. It wouldn't really make a difference to the programs we write right?
Originally posted by Junilu Lacar:
NOW, can we let this thing RIP?
Junilu
Younes
By constantly trying one ends up succeeding. Thus: the more one fails the more one has a chance to succeed.
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime. |