# Method stub

> Mediated Wiki article. Canonical URL: https://mediated.wiki/source/Method_stub
> Markdown URL: https://mediated.wiki/source/Method_stub.md
> Source: https://en.wikipedia.org/wiki/Method_stub
> Source revision: 1316699040
> License: Creative Commons Attribution-ShareAlike 4.0 International (https://creativecommons.org/licenses/by-sa/4.0/)

{{about|placeholder method source code|other uses|Stub (disambiguation)}}
{{Short description|Short and simple version of a method}}

A '''method stub'''<ref name="DaleWeems2004">{{cite book|author1=Nell B. Dale|author2=Chip Weems|title=Programming in C++|url=https://books.google.com/books?id=mxZBPSjSEYUC&pg=PA308|year=2004|publisher=Jones & Bartlett Learning|isbn=978-0-7637-3234-9|pages=308}}</ref> is a short and simple placeholder for a [method](/source/Method_(computer_programming)) that is not yet written for production needs. Generally, a method stub contains just enough code to allow it to be used {{endash}} a declaration with any parameters, and if applicable, a return value.<ref>{{cite web
 | url         = http://www.webopedia.com/TERM/S/stub.html
 | title       = stub
 | date = 23 March 1998
 | publisher   = WEBOPEDIA
 | quote       = 
 | accessdate  = 2012-08-28
}}</ref> 

A method stub may be used to implement an [interface](/source/interface_(computer_science)) that is defined but for which the implementation is not available. 

==Example==

In the following example [pseudocode](/source/pseudocode), the function {{mono|ReadThermometer}} returns a particular value even though ultimately it is supposed to read a value from a [hardware](/source/Electronic_hardware) source. It returns a valid value, allowing consuming code to be runnable. The function ignores the input [parameter](/source/Parameter_(computer_science)) {{mono|source}} which is common for a stub.

 '''function''' ReadThermometer(Source source)
     '''return''' 28
 '''end function'''

==Related==

===Distributed computing===

In [distributed computing](/source/distributed_computing), ''stub'' is like a [mock object](/source/mock_object) {{endash}} [simulate](/source/simulation)s existing code, such as a [procedure](/source/Subroutine) on a remote machine. Such stubs can be useful in [porting](/source/porting).

In [RMI](/source/Remote_Method_Invocation) nomenclature, a stub on the client-side communicates with a [skeleton](/source/Skeleton_(computer_science)) on the server-side.<ref>{{cite book
 | last1         = Freeman
 | first1        = Eric
 | authorlink1   = 
 | last2         = Freeman
 | first2        = Elisabeth 
 | authorlink2   = 
 | last3         = Kathy
 | first3        = Sierra
 | authorlink3   = 
 | last4         = Bert
 | first4        = Bates
 | authorlink4   = 
 | editor1-last   = Hendrickson
 | editor1-first  = Mike
 | editor2-last  = Loukides
 | editor2-first = Mike
 | year          = 2004
 | title         = Head First Design Patterns
 | volume        = 1
 | page          = 440
 | publisher     = O'REILLY
 | format        = paperback
 | isbn          = 978-0-596-00712-6
 | accessdate    = 2012-08-28
 | url           = http://shop.oreilly.com/product/9780596007126.do
}}</ref>

===Windows/MS-DOS===

In [Windows](/source/Windows) and [MS-DOS](/source/MS-DOS), ''stub'' is like a [shim](/source/Shim_(computing)) {{endash}} small interface code left in [conventional memory](/source/conventional_memory) by [self-relocating](/source/self-relocation) resident drivers which move most of themselves into [upper memory](/source/upper_memory), the [high memory area](/source/high_memory_area), [expanded](/source/expanded_memory) or [extended memory](/source/extended_memory) as well as similar stubs to allow the relocated code to communicate with [real-mode](/source/real-mode) DOS in conjunction with [DOS extender](/source/DOS_extender)s (like [DPMI](/source/DOS_Protected_Mode_Interface), [DPMS](/source/DOS_Protected_Mode_Services), [CLOAKING](/source/CLOAKING_(DOS_extender)) or [NIOS](/source/NetWare_I%2FO_Subsystem)).

==See also==

* [Abstract method](/source/Method_(computer_science))
* [Mock object](/source/Mock_object)
* [Dummy code](/source/Dummy_code)
* [Test stub](/source/Test_stub)
* [Glue code](/source/Glue_code)
* [Shim (computing)](/source/Shim_(computing))
* [DOS stub](/source/DOS_stub)

== References ==
{{reflist}}

== External links ==
* [http://www.cs.ncl.ac.uk/research/pubs/articles/papers/94.pdf A Stub Generation System For C++] (PDF)
* [https://web.archive.org/web/20090711150137/http://www.sizovpoint.com/2009/03/java-mock-frameworks-comparison.html Stub/mock frameworks for Java] Review and comparison of stub & mock frameworks for Java

<!-- Fittingly enough, this article is a stub -->

<!--Categories-->
Category:Unit testing
Category:Computer programming folklore
Category:Software development

---
Adapted from the Wikipedia article [Method stub](https://en.wikipedia.org/wiki/Method_stub) by Wikipedia contributors ([contributor history](https://en.wikipedia.org/wiki/Method_stub?action=history)). Available under [Creative Commons Attribution-ShareAlike 4.0 International](https://creativecommons.org/licenses/by-sa/4.0/). Changes may have been made.
