e Polymorphism

Static vs. Dynamic binding

One feature in object-oriented programming languages which is essential to implementing polymorphism is dynamic bindning of functions. Procedural programming languages (like C, Pascal and COBOL etc.) offer static binding.

Static (or early) binding is the concept of resolving a function/method call at compile time.

Function/subroutine calls are bound to specific computer memory locations where functions/subroutines are placed at compile time.

Dynamic (or late) binding is the concept of resolving a method call at run time.

The information available to the compiler at compile time, is the name of an operation, and a branch of the class hierarchy where this operation is defined:

myVehicle -> stop;
At run-time, the correct version of the stop method is selected, i.e. the version which corresponds to the class of the object which the variable myVehicle currently refers to, e.g. stop for Cars, stop for Plane etc.

Note that, the code on the sender side of the program will work even if we later on extend the system to handle new types of vehicles, because the sender expresses WHAT is to be done, instead of HOW. This is an example of polymorphism at work.

A code example of Static vs. Dynamic Bindning.


previous | next | start | contents | dictionary | help | evaluation

© Ericsson Telecom AB, 1995, Stockholm, Sweden