I've been looking on Google for a clear diffrentiation with examples but couldn't find any.
I'm trying to understand the differences between Dynamic Dispatch and Dynamic Binding in Object Oriented languages.
As far as I understand, Dynamic Dispatch is what happens when the concrete method invoked is decided at runtime, based on the concrete type.
For example:
public void doStuff(SuperType object){
object.act();
}
SuperType
has several subclasses. The concrete class of the object will only be known at runtime, and so the concrete act()
implementation invoked will be decided at runtime.
However, I'm not sure what Dynamic Binding means, and how it differs from Dynamic Dispatch.
Please explain Dynamic Binding and how it's different from Dynamic Dispatch. Java examples would be welcome.
1 Answer 1
Dynamic binding is another name for Late Binding. That's where the language ties a data element or method to an object after compilation time.
Wikipedia equates dynamic & late binding:
- Dynamic binding (computing), also known as late binding
links to
http://en.wikipedia.org/wiki/Dynamic_binding_(computing)
Javascript was my first exposure to that, because you can just drop functions into objects willy nilly and do cool things with them.
For example (untested, not guaranteed to work exactly):
var a = Object();
var do = function() { do something };
a.do = do;
a.do();
// neato!
BTW, on a side note, there is some question whether Java is Object-oriented, because one of the original ideas in OO was late binding. Unfortunately, this particular discussion seems to devolve into attempts to define "Object Oriented".
http://c2.com/cgi/wiki?IsJavaObjectOriented
lol!
Under the covers, Dynamic Dispatch and Dynamic Binding may work out the same. But the idea in dynamic dispatch is following some function pointer to see which method to actually invoke, or object to invoke it on. "Binding" is the idea that the method is "bound" to a particular instance (or class of instances) & that's how you identify it.
So they could work together -- a method that's bound to an object with dynamic binding might use dynamic dispatch when you call it.
...
Also dynamic dispatch has more of an OO flavor to it... it's the mechanism behind polymorphism, in which a reference to an object might point to one of multiple implementations. Dynamic dispatch decides at runtime which one to actually run. By contrast, late binding would be dropping in whole new methods that weren't there at compile time.
-
Thanks for replying. I still don't understand the differences between dynamic binding and dynamic dispatch. Could you explain how they differ from each other?Aviv Cohn– Aviv Cohn2014年04月12日 14:45:34 +00:00Commented Apr 12, 2014 at 14:45
-
1Sorry, I clicked "send" too soon. I added some more text -- does that answer your question?sea-rob– sea-rob2014年04月12日 14:47:58 +00:00Commented Apr 12, 2014 at 14:47
-
"Binding" is the idea that the method is "bound" to a particular instance: As far as I know, binding refers to a method name being bound to a method implementation.Giorgio– Giorgio2014年08月10日 21:20:05 +00:00Commented Aug 10, 2014 at 21:20
-
How would you describe the situation (assume Java or .NET) where a base type includes
Foo(Animal)
, derived type overridesFoo(Animal)
but also definesFoo(Cat)
,baseTypeReference
identifies a derived-type instance, client code callsbaseTypeReference(someCat)
? I would describe that as using static binding but dynamic dispatch. Would you agree with such terminology?supercat– supercat2015年04月20日 17:02:54 +00:00Commented Apr 20, 2015 at 17:02
Explore related questions
See similar questions with these tags.