Amethod stub[1] is a short and simple placeholder for amethod that is not yet written for production needs. Generally, a method stub contains just enough code to allow it to be used – a declaration with any parameters, and if applicable, a return value.[2]
A method stub may be used to implement aninterface that is defined but for which the implementation is not available.
In the following examplepseudocode, the functionReadThermometer returns a particular value even though ultimately it is supposed to read a value from ahardware source. It returns a valid value, allowing consuming code to be runnable. The function ignores the inputparametersource which is common for a stub.
function ReadThermometer(Source source)return 28end function
Indistributed computing,stub is like amock object –simulates existing code, such as aprocedure on a remote machine. Such stubs can be useful inporting.
InRMI nomenclature, a stub on the client-side communicates with askeleton on the server-side.[3]
InWindows andMS-DOS,stub is like ashim – small interface code left inconventional memory byself-relocating resident drivers which move most of themselves intoupper memory, thehigh memory area,expanded orextended memory as well as similar stubs to allow the relocated code to communicate withreal-mode DOS in conjunction withDOS extenders (likeDPMI,DPMS,CLOAKING orNIOS).