动态绑定:在动态绑定中,编译器不决定要调用的方法。覆盖是动态绑定的一个完美例子。在覆盖父类和子类时具有相同的方法。动态绑定也称为后期绑定。
消息传递:
计算机中的消息传递是进程之间的通信。它是面向对象编程和并行编程中使用的一种通信形式。 Java的消息传递就像发送一个对象,即从一个线程到另一个线程的消息。当线程没有共享内存并且无法共享监视器或信号量或任何其他共享变量进行通信时使用它。假设我们考虑一个生产者和消费者的例子,同样,生产者将生产什么,消费者只能消费那个。我们大多使用Queue来实现线程之间的通信。
让我们看看动态绑定和消息传递之间的区别:
Dynamic Binding | Message Passing | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Binding refers to the linking of a procedure call to the code to be executed in response to the call. | The process of programming in which communication is involved is known as message passing. | ||||||||||||||||
It allows execution of different codes using the same object at runtime. | It allows developing communication between objects. | ||||||||||||||||
The usage of Dynamic binding to allow executing different codes using the same object at runtime. | It involves three basic steps. They are:
It is the method of linking a procedure call to the relevant code that will be executed only at runtime. |
Message passing is the method of exchanging message between objects in Object Oriented Programming. |
The code associated with the procedure is not known until the program is executed. This process is known as late binding. |
Message passing involves name of the objects, the name of the function and the information to be sent. |
A function call associated with a polymorphic reference depends on the dynamic type of that reference. |
Communication with an object is feasible as long as it is alive. |
In dynamic binding, only at run time the code matching the object under current reference will be called. |
A message for an object is a request for execution of a procedure, and therefore invoke a function in the receiving object that generates the desired result. |
In short, dynamic binding occurs during runtime. |
Message passing occurs between two processes. |
Dynamic binding is also known as dynamic dispatch, late binding or run-time binding. |
Message passing is also known as message exchanging. |
Object based programming does not support dynamic binding. |
Object based programming support message passing. |
Object oriented programming support dynamic binding. |
Object oriented programming also support message passing. |
|