C++ Programming:-
In this tutorial you will learn:-
Dynamic binding
Dynamic memory is the process of linking procedure call to a selected sequence of code (method) at run-time. It means the code to be executed for a selected procedure call isn't known until run-time. Dynamic binding is additionally referred to as late binding or run-time binding.
Dynamic binding is an object oriented programming concept and it's related with polymorphism and inheritance.
Dynamic binding definition
Dynamic binding(dispatch) means a block of code executed with regard to a procedure(method) call is decided at run time.
Dynamic dispatch is usually used when multiple classes contain different implementations of an equivalent method. It provides a mechanism for choosing the function to be executed from various function alternatives at the run-time. In C++, virtual functions are wont to implement dynamic binding
Definitions of Static Binding
When compiler acknowledges all the knowledge required to call a function or all the values of the variables during compile time, it's called “static binding“. As all the specified information are known before runtime, it increases the program efficiency, and it also enhances the speed of execution of a program.
Static Binding makes a program very efficient, but it declines the program flexibility, as ‘values of the variable’ and ‘function calling’ are predefined within the program. Static Binding is implemented during a program at the time of coding.
Overloading a function or an operator are the instance of compile-time polymorphism, i.e. static Binding.
Difference between Static and Dynamic Binding
BASIS FOR COMPARISON | STATIC BINDING | DYNAMIC BINDING | |
---|---|---|---|
Event Occurrence | Events occur at compile time are "Static Binding". | Events occur at run time are "Dynamic Binding". | |
Information | All information needed to call a function is known at compile time. | All information need to call a function come to know at run time. | |
Advantage | Efficiency. | Flexibility. | |
Time | Fast execution. | Slow execution. | |
Alternate name | Early Binding. | Late Binding. | |
Example | Overloaded function call, overloaded operators. | Virtual function in C++, overridden methods in java |
0 comments:
Post a Comment
If you have any doubt, please let me know