Dynamic binding establishes the link between the function call, and function signature. While writing a program, a function is invoked in the main function through function name. Compiler generates coded address of the function signature and applies at the function call position in the caller program. The control gets transferred to the address available at function call position, at the time of execution. This process is called dynamic binding. In dynamic binding, the method call is bonded with the body of the method at the run time.

 

Method overriding is the example of dynamic binding as in overriding both base and derived class have same method name and the type of the object determines which method is to be executed. And the type of object is determined at run time. Since the binding is done at run time, it is also known as late binding.

 

Dynamic Binding Vs Static Binding

 

Apart from dynamic binding, OOPs also facilitates the concept of static or early binding. In static binding the compiler can resolve the function call at compile time only. Hence, the linkage between the function call, and function definition is generated at compile time. Function Overloading is the example of static binding.

In static binding, all the information which is needed to call a function is available at compile time while in the dynamic binding the information needed for a function call can’t be determined at compile time.

Static binding is achieved through normal function calls and function overloading whereas dynamic binding is achieved using virtual functions.

 

 Advantages of Dynamic Binding in OOPs

• It provides flexibility to the program as you can create a single function which can handle the different type of objects at the time of the program execution i.e. during run time.

• The size of the code gets reduced and memory can be utilized more efficiently.

• It makes the source code more readable and amicable to the user.

Leave a Reply

Your email address will not be published. Required fields are marked *