Stub (programming)

from Wikipedia, the free encyclopedia

A stub (of English stub , stump, stub, stump) or socket referred to in the software development one - usually relatively simple and short - program code that stands in place of another, usually more complex program code. The actual program code that is replaced by the stub has not yet been developed ( top-down approach) or on another computer or in another memory area . If the code is in a different location, the stub is the local point of contact to easily address software components that would otherwise only be accessible via complex protocols and to hide this complexity. A stub then corresponds to the design pattern of a substitute .

In particular, stubs are used in the development of distributed systems : The functionality of a remote software system that can only be reached via a network is made available on the local system in the form of a "stub component". This stub component can be addressed by the software of the local system as if the functionality of the remote system were available locally ( access transparency ). Rather than this desired function actually implement that Stubkomponente translates the requests into network calls ( marshaling ), communicates with the remote system and delegated the action at this. This communication process remains hidden from the system using it.

In the case of communication according to the client-server model ( RPC , RMI ), the local representative room on the client is also called proxy . With various techniques, a basic framework ( skeleton ) for the counterpart on the server can be created from an abstract description .

Mono- and polymorphic stubs

A program that calls the method of an interface must determine the underlying data type the first time it is accessed.

Once the data type has been determined, a monomorphic stub is generated that implements a function for accessing the appropriate method for the respective data type. The stub can be saved in order to optimize another call of the interface for another object. However, if the other object is of a different type, a new monomorphic stub must be created. A monomorphic stub therefore has the disadvantage that it is only suitable for a specific, concrete data type.

In contrast to this, a polymorphic stub has a hash table which points to a list of stub functions. The polymorphic stub can then - depending on the respective data type - call the appropriate function. When a new data type is called, a function optimized for this is generated and added to the polymorphic stub. The polymorphic stub is slower because of the lookup.

Some implementations, such as the common language runtime, support both mono- and polymorphic stubs. A heuristic decides which stub type is used .

See also

Individual evidence

  1. a b c Ben Watson: Writing High-Performance .NET Code . 2014, ISBN 978-0-9905834-3-1 (English).