ArticleslgStudy

computer science

Late binding

Late binding is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Late binding rather than just read about it. In short: Late binding is the act or mechanism of binding two software entities at runtime as opposed to early binding which occurs before the program starts – such as design or build times. The implementation of late binding differs by context.

Key takeaways

  • Late binding belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Late binding to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Late binding from memory before moving on to harder problems.

Reference excerpt

Late binding is the act or mechanism of binding two software entities at runtime as opposed to early binding which occurs before the program starts – such as design or build times. The implementation of late binding differs by context. The term dynamic binding is sometimes used for the same concept, but is more commonly refers to dynamic scope.

History The term "late binding" dates back to at least the 1960s, where it can be found in Communications of the ACM. The term was widely used to describe calling conventions in languages like Lisp, though usually with negative connotations about performance. In the 1980s, Smalltalk popularized object-oriented programming (OOP) and with it late binding. Alan Kay once said, "OOP to me means only messaging, local retention, and protection and hiding of state-process, and extreme late-binding of all things. It can be done in Smalltalk and in LISP. There are possibly other systems in which this is possible, but I'm not aware of them." In the 1990s, COM was commonly used. It provided both a binary, early binding as well as a late binding based on name lookup. In 2000, Alex Martelli coined the term duck typing to refer to a form of polymorphism that leveraged the same kind of name lookup as COM late binding. A runtime supports duck typing if it is interpreted or if it supports type introspection.

Examples

In C++ In C++, late binding (also called "dynamic binding") refers to what normally happens when the virtual keyword is used in a method's declaration. Typically, a call requires a lookup via a virtual table.

In COM In Component Object Model (COM), a late-bound method call is performed via the IDispatch interface. This is performed by calling GetIDsOfNames() to look up a method by name and then Invoke to execute the method. Some contexts provide ease-of-use support for calling this interface. For example, in Visual Basic 6, methods are called late-bound for a variable declared as Object. In contrast, with early binding, the compiler fixes types of variables and expressions. The primary advantage of using late binding in COM programming is that one is not required to reference the providing library at compile time. This makes the compilation process more resistant to version conflicts, in which the class's v-table may be accidentally modified. This is not an issue in just-in-time compilation runtimes such as .NET and Java, because the v-table is created at runtime.

In .NET In .NET, late binding refers to overriding a virtual method like C++ or implementing an interface. The compiler builds virtual tables for every virtual or interface method call which is used at run-time to determine the implementation to execute. Also like COM and Java, the Common Language Runtime provides reflection APIs that can make late binding calls. The use of these calls varies by language. With C# 4, the language also added the "dynamic" pseudo-type. This would be used in place of the Object type to indicate that late binding is desired. The specific late binding mechanism needed is determined at runtime using the Dynamic Language Runtime as a starting point. Visual Basic uses them whenever the variable is of type Object and the compiler directive "Option Strict Off" is in force. This is the default setting for a new VB project. Prior to version 9, only .NET and COM objects could be late bound. With VB 10, this has been extended to DLR-based objects.

In Java There are three definitions for late binding in Java. Early documents on Java discussed how classes were not linked together at compile time. While types are statically checked at compile time, different implementations for classes could be swapped out just prior to runtime simply by overwriting the class file. As long as the new class definition had the same class and method names, the code would still work. In this sense it is similar to the traditional definition of late binding. Currently, it is popular to use the term late binding in Java programming as a synonym for dynamic dispatch. Specifically, this refers to Java's single dispatch mechanism used with virtual methods.

In dynamically-typed languages In most dynamically-typed languages (such as JavaScript), the list of methods on an object can be altered at runtime. This requires late binding.

In Lisp In Lisp, late bound global function calls are efficiently looked up at runtime via a symbol's function cell. These function bindings are mutable. Example using an interactive Clozure Common Lisp session:

In PL/SQL and Ada When using early binding between Ada and a database-stored procedure, a timestamp is checked to verify that the stored procedure has not changed since the code was compiled. This allows for faster executions and prevents the application from running against the wrong version of a stored procedure. When using late binding the timestamp check is not performed, and the stored procedure is executed via an anonymous PL/SQL block. While this can be slower, it removes the need to recompile all of the client applications when a stored procedure changes. This distinction appears to be unique to PL/SQL and Ada. Other languages that can call PL/SQL procedures, as well as other database engines, only use late binding.

Dynamic linking Dynamic linking (and related dynamic linkage) is a form of late binding for importing a code library.

Criticism

… excerpt ends here. Continue reading the full article.

Worked examples

Example 1 — a first encounter with Late binding

Start with the simplest possible case. Write down what Late binding claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Late binding before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Late binding ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Late binding

In research
Late binding appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Late binding in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Late binding is common in secondary-school and first-year university syllabi. It links to neighbouring topics Method (computer programming), Programming language concepts, so understanding it makes those chapters shorter.
In everyday life
Look for Late binding outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Late binding” →

How to study Late binding in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Late binding means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Late binding out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Late binding in simple terms?

Late binding is the act or mechanism of binding two software entities at runtime as opposed to early binding which occurs before the program starts – such as design or build times. The implementation of late binding differs by context.

Why does Late binding matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Late binding?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Late binding.

Tags

  • Method (computer programming)
  • Programming language concepts

Keep exploring