A method stub or simply stub
in
software development
Software development is the process of conceiving, specifying, designing, programming, documenting, testing, and bug fixing involved in creating and maintaining applications, frameworks, or other software components. Software development inv ...
is a piece of code used to stand in for some other programming functionality. A stub may
simulate
A simulation is the imitation of the operation of a real-world process or system over time. Simulations require the use of models; the model represents the key characteristics or behaviors of the selected system or process, whereas the ...
the behavior of existing code (such as a
procedure
Procedure may refer to:
* Medical procedure
* Instructions or recipes, a set of commands that show how to achieve some result, such as to prepare or make something
* Procedure (business), specifying parts of a business process
* Standard operat ...
on a remote machine; such methods are often called mocks) or be a temporary substitute for yet-to-be-developed code. Stubs are therefore most useful in
porting
In software engineering, porting is the process of adapting software for the purpose of achieving some form of execution in a computing environment that is different from the one that a given program (meant for such execution) was originally des ...
,
distributed computing
A distributed system is a system whose components are located on different networked computers, which communicate and coordinate their actions by passing messages to one another from any system. Distributed computing is a field of computer sci ...
as well as general software development and
testing.
An example of a stub in
pseudocode might be as follows:
temperature = ThermometerRead(Outside)
if temperature > 40 then
print "It is hot!"
end if
function ThermometerRead(Source insideOrOutside)
return 28
end function
The above pseudocode utilises the function , which returns a temperature. While would be intended to read some hardware device, this function currently does not contain the necessary code. So does not, in essence,
simulate
A simulation is the imitation of the operation of a real-world process or system over time. Simulations require the use of models; the model represents the key characteristics or behaviors of the selected system or process, whereas the ...
any process, yet it ''does'' return a legal value, allowing the main program to be at least partially tested. Although it accepts the
parameter
A parameter (), generally, is any characteristic that can help in defining or classifying a particular system (meaning an event, project, object, situation, etc.). That is, a parameter is an element of a system that is useful, or critical, when ...
of type , which determines whether inside or outside temperature is needed, it does not use the actual value passed (
argument
An argument is a statement or group of statements called premises intended to determine the degree of truth or acceptability of another statement called conclusion. Arguments can be studied from three main perspectives: the logical, the dialect ...
) by the caller in its logic.
A stub is a routine that doesn't actually do anything other than declaring itself and the parameters it accepts and returning something that is usually the values expected in one of the "happy scenarios" for the caller. Stubs are used commonly as placeholders for implementation of a known interface, where the
interface is finalized/known but the implementation is not yet known/finalized. The stub contains just enough code to allow it to be compiled and linked with the rest of the program. In
RMI
RMI may refer to:
Science and technology
* Radio-magnetic indicator, an instrument used in aircraft navigation
* Repetitive motion injury, an injury to the musculoskeletal and nervous systems
* Richtmyer–Meshkov instability, an instability occu ...
nomenclature, a stub on the client-side communicates with a
skeleton on the server-side.
In the context of
DOS and
Windows
Windows is a group of several proprietary graphical operating system families developed and marketed by Microsoft. Each family caters to a certain sector of the computing industry. For example, Windows NT for consumers, Windows Server for ...
, the term ''stub'' is also used in a fashion like
shim to describe the small areas of interface code left in
conventional memory by
self-relocating
In computer programming, a self-relocating program is a program that relocates its own address-dependent instructions and data when run, and is therefore capable of being loaded into memory at any address. In many cases, self-relocating code is a ...
resident drivers which move most of themselves into
upper memory, the
high memory area,
expanded or
extended memory as well as similar stubs to allow the relocated code to communicate with
real-mode DOS in conjunction with
DOS extenders (like
DPMI,
DPMS,
CLOAKING or
NIOS).
The small pieces of dummy code branched into—so as to allow a graceful exit when invoking a
fat binary in the wrong environment—are also called (code) stubs.
See also
*
Abstract method
*
Mock object
*
Dummy code
*
Test stub
*
Glue code
*
Shim (computing)
*
DOS stub
References
{{reflist
External links
A Stub Generation System For C++(PDF)
Review and comparison of stub & mock frameworks for Java
Unit testing
Computer programming folklore
Software development