What is a dynamic link?

In computer science, the name of the Association of Identifier, such as the Function or Variable Name, to the Part of the Code or Data. In the most common scenario, static binding is known at the time of compilation. In dynamic binding, an object mapped by a function is known at the time of compilation and can only be determined during the program running. For this reason, the dynamic bond is also called a late bond. Although dynamic binding offers flexibility that is not available with static binding, it also includes more performance costs than static binding. Polymorphism allows you to implement the same method name in different ways. If the code is not written in such a way that the exact method cannot be determined at the time of compilation, a dynamic binding must be used.

For example, the "shape" class may have a method called "Getearea" because each shape has an area. "Circular" subclass "shape", however, would implement "Getearea" differently from the wayclass "square". Therefore, if a new "shape" object is created, and if the code calls the "Getarea" method in this shape, the compiler will not have any way to know whether the shape ends up as a circle or square and therefore will not know which method of getarea calls. This is an example of a dynamic binding, because the right method of getarea will only be mapped while running after the program knows what shape is the object.

Dynamic binding allows the flexibility of the use of abstract methods without knowing which specific implementation will be used. In the "shape" example, the code can be written to prevent dynamic binding by explicit use of this logic: if the shape is a circle, call the Getearea method; Otherwise, if the shape is a square, call a specific method of Getearea toss. The advantage of a dynamic link is that the code is cleaner and more maintained than the alternative. In the example of a static link, code duplicity occurs and the code must be updated whenever a new shape is added.

disadvantages of dynamic bindingare performance and safety. In static binding, the compiler knows exactly what code is to call and can optimize the code for more efficient startup. The type of type of type may be a problem, because in some implementation of dynamic bonds, the method can be triggered to an object that does not support this method. For example, the "Getarea" method can be induced on an object that is not a shape and therefore does not have the "Getarea" method, which could lead to a run-time error. Statical binding would prevent this scenario by increasing compilation errors.

IN OTHER LANGUAGES

Was this article helpful? Thanks for the feedback Thanks for the feedback

How can we help? How can we help?