2.2.1 Realizing interfaces

Objects provided by a component conforming to a second-generation component model are never accessed directly, they are always accessed through one of the interfaces they implement. As components may be written in languages with no native support for interfaces, they are defined in an auxiliary descriptive language that allows no code, only definitions of interfaces, their operations and the types that are used. These languages are broadly known as interface description languages, widely known by the abbreviation IDL. (A large number of incompatible languages lay claim to the name “IDL.”)

Code generators that come with component model implementations, known as IDL compilers, take an IDL file as input and generate language bindings for a supported programming language.1 Language bindings make it possible to access components from multiple languages and ideally conform to the target language to a great extent, making components feel like a natural part of the target environment. Some language bindings, typically for scripting languages, may not allow components to be authored in the target language. Such languages are restricted to accessing components written in other languages.

An operation in an interface is mapped to the most appropriate construct in the target language. For a procedural language, this is a procedure or a function; for an object-oriented language, this is a method or an operation. A type is mapped to the native type most appropriate for the target language—a “number” type used in an IDL file may be mapped to the “double” type in a binding for the C language, for instance. If the execution of an operation fails, this is normally communicated by throwing an exception in a target language that supports exceptions, or by returning an error code in a language with no such support. (True return values are communicated using output arguments when the native return value is used for error information.)

Footnotes

  1. Language bindings can also be generated from other representations of interfaces, such as COM type libraries, which contain roughly the same information as IDL files in a format that is more easily parsed.