• Post Reply Bookmark Topic Watch Topic
  • New Topic

Is Polymorphism and Late Binding the same or different?  RSS feed

 
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Is Polymorphism and Late Binding the same or different?Kindly let me know.

Regards,
Sathya
 
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'd say that late binding is how (runtime) polymorphism is implemented.
 
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Late binding" is a somewhat vague terminology, at least as it's used across languages. (I think I'm among friends here, so I can type in the next sentence...) When I was learning VB(6) they used the term late binding to describe what happens when you apply a method to a variable of type Object. What happens in this case is that at *run-time* the interpreter searches to see if the object referenced even *has* the given method. This, of course, would have been resolved at compile-time if this were transmogrified into Java, and what is happening here sounds more like reflection to my ears, but it goes by late binding in VB.
 
ranger
Sheriff
Posts: 17309
11
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually to add to Jeff's VB analogy. They did have the correct definition of Late Binding meaning that the creation and knowledge of what type to create is all determined at runtime.

So if I had a string that had the name of a Class that was defined in code at runtime.

String s = "MyClass"

late binding would take that string and use it to create the object. Just like Jeff said about Reflection, it is relatively the exact same thing.

so

Object a = new Object(s);

so it creates a MyClass object.

Mark
 
Mark Spritzler
ranger
Sheriff
Posts: 17309
11
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh by the way, my code above is neither VB or Java, just sort of pseudocode.

Mark
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mark, that's late binding, too. But late binding applied at the method level is exactly what we call runtime polymorphism, or so it seems to me. (Keep in mind that in dynamically typed OO languages the existence of a method on the referenced type isn't checked at compile time, either.)

See http://en.wikipedia.org/wiki/Late_binding
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!