2.2.4 Late binding versus very late binding

The implementations of classes are, as noted, always hidden behind their interfaces. As such, a client is unaware of the precise implementation it is calling, and thus cannot be bound to an implementation at compile-time. Retrieving a reference to the implementation is done at runtime. The client does, however, have compile-time knowledge of the layout of the interface—it knows, at compile-time, what operations are available, their arguments and their types. It thus binds to the implementation of the interface dynamically, but checks the validity of calls statically. Again, this is known as dynamic dispatch, or late binding.

In some environments, it may not be possible to have compile-time knowledge of interfaces and their operations. An interpreter for a scripting language, to mention the most prominent example, is not compiled against the myriad of components that a script may want to access. As such, the validity of calls must be checked at runtime. This requires that metadata in the form of runtime type information is not only available at compile-time, but also at runtime. This is known as very late binding.

Some component models, notably COM, take the approach of supplying a standard, domain-agnostic interface that is used for dynamically checked invocations (in COM, this interface is named IDispatch). Classes that wish to support being invoked by environments that need to check invocations at runtime must also implement this interface (often in addition to interfaces to which calls are checked statically). Script interpreters that support such a component model have compile-time knowledge of this interface, and facilitate access to it from scripts. The implementation of this interface can use self-contained code specific to a certain class to check invocations, or the implementation can be generic and rely on runtime-accessible type information deployed to end-users’ systems (discussed in section 4.4.3). Other component models, notably CORBA, require clients to use a single system-provided, domain-agnostic implementation to invoke calls using very late binding (which also requires the presence of type information at runtime).