:Method stub
{{about|placeholder method source code|other uses|Stub (disambiguation)}}
{{Short description|Short and simple version of a method}}
A method stub{{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}} is a short and simple placeholder for a method 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.{{cite web
| url = http://www.webopedia.com/TERM/S/stub.html
| title = stub
| date = 23 March 1998
| publisher = WEBOPEDIA
| quote =
| accessdate = 2012-08-28
}}
A method stub may be used to implement an interface that is defined but for which the implementation is not available.
Example
In the following example pseudocode, the function {{mono|ReadThermometer}} returns a particular value even though ultimately it is supposed to read a value from a hardware source. It returns a valid value, allowing consuming code to be runnable. The function ignores the input parameter {{mono|source}} which is common for a stub.
function ReadThermometer(Source source)
return 28
end function
Related
=Distributed computing=
In distributed computing, stub is like a mock object {{endash}} simulates existing code, such as a procedure on a remote machine. Such stubs can be useful in porting.
In RMI nomenclature, a stub on the client-side communicates with a skeleton on the server-side.{{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
}}
=Windows/DOS=
In Windows and DOS, stub is like a shim {{endash}} small interface code left in conventional memory by self-relocating 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).
See also
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