Share on Facebook Share on Twitter Email
Answers.com

Dynamic binding

 
Wikipedia: Dynamic binding (computer science)

In object oriented programming, dynamic binding means determining the exact implementation of a request based on both the request (operation) name and the receiving object at the run-time. It often happens when invoking a derived class's member function using a pointer to its super class. The implementation of the derived class will be invoked instead of that of the super class. It allows substituting a particular implementation using the same interface and enables polymorphism.

Example

Suppose all life-forms are mortal. In object oriented programming, we can say that the Person and Plant classes must implement the Mortal interface, which contains the method die().

Persons and Plants die in different ways; for example, Plants do not have hearts that stop. Dynamic binding is the practice of figuring out which method to invoke at runtime. For example, if we write

void kill(Mortal m) {
  m.die();
}

it's not clear whether m is a Person or a Plant, and thus whether Plant.die() or Person.die() should be invoked on the object. With dynamic binding, the m object is examined at runtime, and the method corresponding to its actual class is invoked.

See also


Search unanswered questions...
Enter a question here...
Search: All sources Community Q&A Reference topics
 
 

 

Copyrights:

Wikipedia. This article is licensed under the Creative Commons Attribution/Share-Alike License. It uses material from the Wikipedia article "Dynamic binding (computer science)" Read more