Glue code

From Wikipedia, the free encyclopedia
Jump to: navigation, search

In programming, Glue Code is code that serves solely to "glue together" different parts of code that would not otherwise be compatible. It does not contribute any functionality towards meeting the program's requirements, but instead Glue Code often appears in code written to let existing libraries or programs inter-operate, as in language bindings or foreign function interfaces like the Java native interface, or when mapping objects to a database using object-relational mapping, or when integrating two or more commercial off-the-shelf programs. Glue code may be written in the same language as the code it is gluing together, or in a separate glue language.


Glue code usually does not serve any use in calculation or computation. Rather it serves as a proxy between two incompatible parts of software, to make them compatible. The standard practice is to keep logic out of the glue code and leave that to the code blocks it connects to.[1] While glue code can enable the transfer of information between computer languages, it is not required to do so but very helpful.

It is quite common for different parts of the program to alert each other about different events or errors that have occurred.[2] This is especially useful when the different factions of a program are used in conjunction with external devices or user interfaces. Glue code is essential when trying to obtain data from other components in the system. Some glue code generators allow user-specified data to be passed between code modules. For example, a submit button on a user-interface forum must notify the application that the user has pressed submit. However, moving large pieces of data between code blocks using connecting code is not always reliable.

Glue code can be used to connect code modules of any size- from small functions to large libraries. Depending on the amount of proxy code generated for this purpose, there may be a significant amount of code bloat and overhead, so connecting small pieces of code in this way may not always be ideal. When synchronizing calls to large libraries or merging large code repositories, on the other hand, a small amount of glue code can be an invaluable way to bring functionality where it might otherwise be unavailable.


Glue code allows interconnection and integration of programs and different languages. Glue code often consists of the same languages that it is connecting. Specifically, when it connects distinct computer languages, it contains code pieces specific to each code module it is putting together.[3] For example, to connect a component using Java and a component using C#, the glue code would contain both Java and C# in that file. So long as the factions that the code is connecting don't change, the glue code doesn't need to change; although it may need to be updated. Generated files are rarely changed by a developer. The end-user should never have access or be able to change the glue code.

Glue code can connect code modules of any size. Depending on the amount of proxy code generated, it can glue together small functions to large libraries. Because of code bloating and overhead, glue code is best used on larger files. On the other hand, merging large libraries can make it inefficient for a small amount of glue code to bring functionality.

Glue code is very efficient in rapid prototyping environments where several components are quickly put together into a single language or framework.

Glue code vs. XML[edit]

Extensible Markup Language (XML) data is often confused with glue code. Many believe they are very similar, but in fact each serve a quite different purpose. XML is a markup language while glue code is a scripting pattern.[4] XML adds descriptive information to existing text or data and organizes it to make it easier to interpret. Both are able to be proxies to move data, but XML is static and far more limited when transferring code blocks. Glue code manipulates data and allows movement between code blocks while XML updates and classifies data.


Several programmers use scripts to parameterise the component with specific interactions.[5] When that particular faction needs to communicate with the other factions it is glued with, it runs the appropriate script in the language interpreter. However, because each component is independent and is only connected to another component from this glue code, the behavior of a component and its interactions can change during the execution of the script; it's not fixed.

Low level programming languages suffer from performance penalties because glue code must run through the language interpreter. If performance is crucial, using Configuration Scripting is often preferred to directly connect binary interfaces of components. In object oriented scripting languages, glue code often rids the need of class hierarchies and large number of classes.

See also[edit]


[1] [2] [3] [4] [5] [6]

  1. ^ University of Ottawa: Object Oriented Software Engineering, Glue Code Def.
  2. ^
  3. ^
  4. ^
  5. ^
  6. ^