|[9 earlier articles]|
|Re: Polymorphism vs. Overloading firstname.lastname@example.org (1994-10-28)|
|Re: Polymorphism vs. Overloading email@example.com (1994-10-25)|
|Re: Polymorphism vs. Overloading firstname.lastname@example.org (1994-10-31)|
|Re: Polymorphism vs. Overloading email@example.com (1994-10-31)|
|Re: Polymorphism vs. Overloading firstname.lastname@example.org (Rob MacLachlan) (1994-10-25)|
|Re: Polymorphism vs. Overloading email@example.com (1994-10-31)|
|Re: Polymorphism vs. Overloading Mike.Chapman@muc.de (Mike Chapman) (1994-10-31)|
|Re: Polymorphism vs. Overloading firstname.lastname@example.org (1994-10-31)|
|Re: Polymorphism vs. Overloading email@example.com (1994-10-31)|
|Re: Polymorphism vs. Overloading firstname.lastname@example.org (1994-10-26)|
|Re: Polymorphism vs. Overloading email@example.com (1994-10-31)|
|Re: Polymorphism vs. Overloading firstname.lastname@example.org (1994-10-31)|
|Re: Polymorphism vs. Overloading email@example.com (Martin Odersky) (1994-10-31)|
|[15 later articles]|
|From:||Mike Chapman <Mike.Chapman@muc.de>|
|Date:||Mon, 31 Oct 1994 22:23:00 GMT|
Gabriela O. de Vivo <firstname.lastname@example.org> wrote:
>Last week I was invited to join a Thesis (MsC) presentation.
>At some point a question raised about the exact difference between
>Polymorphism and Overloading.
Joseph H Allen (email@example.com) wrote:
: The difference is purely syntactical. Calls to overloaded functions look,
: well, like function calls. Calls to polymorphic functions require a dot or
: '->' somewhere. Really, that's the only difference. Artificial semantic
: restrictions placed by certain languages aside, you can always move the
: identifier or address-expression from the left of the dot into the
: parenthasis as the first argument to generate an equivelent overloaded
: function call.
No, I think this is wrong.
The big difference is that how the selection of the function is done.
The selection of an overloaded function occurs statically based upon
the declared types of the parameters.
The selection of a polymorphic function depends on the types of the
object (the parameter before the '.' or '->' in most languages)
at the time of invocation.
So if you have Shape objects of which Rectangles and Circles
are specific kinds of shapes and have say an overloaded
function display and a polymorphic function draw then
x := r; -- Rectangles and circles are shapes
y := c; -- so these assignments are type safe.
For the overloaded function display
display(x) means Shape's display
display(y) means Shape's display
display(c) means Circles display
display(r) means Rectangles display
Then for the polymorphic function draw
x.draw means Rectangles draw
y.draw means Circules draw
r.draw means Rectangles draw
c.draw means circles draw
All (?) OO languages support the polymorphic version.
Almost all OO languages support only one special argument
which controls the dispatching (the one before the '.' or
'->'). As far as I am aware Ada 9x allows dynamic dispatching
on more than one argument and does not use the '.' notation.
Overloading is just an excuse to avoid thinking of meaningful
names for some of your functions and has no real conceptual
significance. You could just have well have written
Smalltalk supports only the draw kind of call,
Ada 83, Algol 68 support only the display kind of call.
'C' has overloaded standard operators (eg '+' on int's
unsigned ints, double's etc).
Ada 83 has overloaded everything (and overloads on the
result type as well as the arguments which is a concept
which seems to be hard to explain to inexperienced
Return to the
Search the comp.compilers archives again.