aspose file tools*
The moose likes OO, Patterns, UML and Refactoring and the fly likes Static/Compile-time Polymorphism ?? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » OO, Patterns, UML and Refactoring
Bookmark "Static/Compile-time Polymorphism ??" Watch "Static/Compile-time Polymorphism ??" New topic
Author

Static/Compile-time Polymorphism ??

Sudharsan Govindarajan
Ranch Hand

Joined: Jul 03, 2002
Posts: 319
Does OOP really has something like this, Compile-time Polymorphism or Static Polymorphism? I have seen some authors using this term for 'function overloading'. Is it technically correct? (or should I say object-orientedly ) My Idea was that all Polymorphism happens at run-time and that is why it is 'Poly-morphism'.
thanks
Sudharsan
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4757
    
    7

This has been the subject of long debates here in JavaRanch and elsewhere, usually under the topic heading "Is Overloading Polymorphism?" (do a search in Java in General or Java Programmer Certification or maybe even this forum).
At the risk of starting yet another long thread about this, there are those who say that overloading is not polymorphism but
my personal view is that it is one (albeit weaker)form of polymorphism since it fits the description of "many forms".


Junilu - [How to Ask Questions] [How to Answer Questions]
Sudharsan Govindarajan
Ranch Hand

Joined: Jul 03, 2002
Posts: 319
I was afraid that I may be repeating a topic. But my search results in this forum with the keywords in this post's title did'nt produce anything relevant. So I went ahead and posted this. I did'nt search other forums.
Junilu,
Though it fits the description of 'many forms', it does'nt fit 'same message to an object'. IMHO, different signatures of a method is different messages.
thanks
sudharsan
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Originally posted by Sudharsan G'rajan:
IMHO, different signatures of a method is different messages.

Mhh, why? How do you define "message"?


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Vikrama Sanjeeva
Ranch Hand

Joined: Sep 02, 2001
Posts: 756
Hi,
Patrick Nauhgton, member of original Java teams says, Overloading is one of the ways that Java implements polymorhism.
If u look into the literal meaning of Polymorhsim i.e Poly means many and morh means forms, then i think it is legal to say that Overlpading is a notion of polymorphsim.
Well, it is correct that there many pplz. at ranch differ in there views about overloading concept of polymorphsim.I think when something is unclear or disputed then we should look at the literal meaning and the authentic and experienced pplz. to clairfy concepts.
Bye,
Viki.


Count the flowers of your garden, NOT the leafs which falls away!
Prepare IBM Exam 340 by joining http://groups.yahoo.com/group/IBM340Exam/
Sudharsan Govindarajan
Ranch Hand

Joined: Jul 03, 2002
Posts: 319
Originally posted by Ilja Preuss:

Mhh, why? How do you define "message"?

Conside this situation. There is an object called Rock.
It has the following methods,
move()
move(int ft)
move(int x, int y)
Although all the 3 methods are 'move', the message sent to the 'Rock" object is not the same.
The first one just says move, whereas the second one may say move the rock to 'ft'
feet distance and third one may say move it to the location x, y in terms of co-ordinates.
Are'nt they different?
I think a message does not diretly correspond to the method name alone...
sudharsan
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Originally posted by Sudharsan G'rajan:

Conside this situation. There is an object called Rock.
It has the following methods,
move()
move(int ft)
move(int x, int y)
Although all the 3 methods are 'move', the message sent to the 'Rock" object is not the same.
The first one just says move, whereas the second one may say move the rock to 'ft'
feet distance and third one may say move it to the location x, y in terms of co-ordinates.
Are'nt they different?

Well, they all share a common intent - moving the Rock. Of course the could be wildly different in implementation - but that's true for dynamic polymorphism, too.
Consider this situation:
There is a class called PrintStream. It has the following methods:
print(int)
print(char)
print(float)
print(double)
print(boolean)
print(Object)
The first says "print an int", whereas the second says "print a char" etc.
Now, if you write
printStream.print(v)
you don't need to care which type v is of. The correct method will be determined at compile time. Isn't this a form of polymorphism?
Sudharsan Govindarajan
Ranch Hand

Joined: Jul 03, 2002
Posts: 319
Well! You are making my point stronger.

The first says "print an int", whereas the second says "print a char" etc.

This is what I say. They send different messages to the printStream object.

you don't need to care which type v is of. The correct method will be determined at compile time. Isn't this a form of polymorphism?
[/code]

But your argument seems pretty much valid.
sudharsan
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Originally posted by Sudharsan G'rajan:
The first says "print an int", whereas the second says "print a char" etc.
--------------------------------------------------------------------------------

This is what I say. They send different messages to the printStream object.

Or they send the same message ("print this thing") with different "things".
There are in fact languages in which the argument types are also evaluated at runtime instead of compile time (for example in the common lisp object system, afaik). So, here we have the same type of polymorphism, just dynamically instead of statically, so it seems to me...
Sudharsan Govindarajan
Ranch Hand

Joined: Jul 03, 2002
Posts: 319
Originally posted by Ilja Preuss:

There are in fact languages in which the argument types are also evaluated at runtime instead of compile time (for example in the common lisp object system, afaik)

This is news to me. Is there an object oriented extension to Common LISP?

So, here we have the same type of polymorphism, just dynamically instead of statically, so it seems to me...

Ilja, you seem to have cornered me, But still I'm not convinced.
My logic still questions me about the first example (Rock & move). Your example was talking abt methods with same number of arguments and the messages were kinda 'Print this thing' or 'Print this and that' or "Print this, that and another one'. But my example was talking abt 'move this', 'move this by this number of feet' and 'move this to position x,y'.
I still need something else to convince my reasoning.
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4757
    
    7

As I said before, this topic has been discussed at great length here and elsewhere and I doubt if any amount of reasoning can persuade someone to change their point of view once it's been chosen. You guys are more than welcome to attempt to do so anyway.
Academic differences aside, what does it really matter anyway? Does the distinction have any profound effect on the way you design and write Java programs? I highly doubt it. The ability to overload methods is a very useful feature and I doubt that those using it--apart from the extremely anal individuals--really give a second thought as to whether or not it is a form of "pure polymorphism."
I say, "Just Java and be happy."
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Originally posted by Sudharsan G'rajan:
This is news to me. Is there an object oriented extension to Common LISP?

Yes: http://www-2.cs.cmu.edu/Groups/AI/html/cltl/clm/node260.html
Ilja, you seem to have cornered me, But still I'm not convinced.
My logic still questions me about the first example (Rock & move). Your example was talking abt methods with same number of arguments and the messages were kinda 'Print this thing' or 'Print this and that' or "Print this, that and another one'. But my example was talking abt 'move this', 'move this by this number of feet' and 'move this to position x,y'.

Well, aren't these "multiple forms" to move a rock?
But I agree with Junilu - it doesn't matter that much. Just be aware that different people use the word for different things.
Just found those two examples: http://www.javaworld.com/jw-02-2000/jw-02-jsr.html and http://c2.com/cgi/wiki?MultiMethods :roll:
Sudharsan Govindarajan
Ranch Hand

Joined: Jul 03, 2002
Posts: 319
Ilja, thank you so much for taking the pains to argue with an idiot
I too agree with Junilu, this is not going to make a big difference in the way we are doing programming. Still, argument is enjoyment
Sudharsan
[ February 04, 2003: Message edited by: Sudharsan G'rajan ]
Sudharsan Govindarajan
Ranch Hand

Joined: Jul 03, 2002
Posts: 319
Ilja, thanks for all those links. They are interesting!
sudharsan
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Static/Compile-time Polymorphism ??