Sei sulla pagina 1di 3

10/30/12

Wrapper f unction - Wikipedia, the f ree ency clopedia

Wrapper function
From Wikipedia, the free encyclopedia

A wrapper function is a function in a computer program whose main purpose is to call a second function[1] with little or no additional computation. This is also known as method delegation. Wrapper functions can be used for a number of purposes.

Contents
1 Adapting class/object interfaces 2 Code testing 3 Multiple inheritance 4 Programming convenience 5 Library functions and system calls 6 See also 7 References

Adapting class/object interfaces


Main article: Adapter pattern Wrapper functions can be used to adapt an existing class or object to have a different interface. This is especially useful when using existing library code.

Code testing
Wrapper functions can be used to write error checking routines for pre-existing system functions without increasing the length of a code by a large amount by repeating the same error check for each call to the function.[2] All calls to the original function can be replaced with calls to the wrapper, allowing the programmer to forget about error checking once the wrapper is written. A test driver is a kind of wrapper function that exercises a code module, typically calling it repeatedly, with different settings or parameters, in order to rigorously pursue each possible path. It is not deliverable code, but is not throwaway code either, being typically retained for use in regression testing. An interface adaptor is a kind of wrapper function that simplifies, tailors, or amplifies the interface to a code module, with the intent of making it more intelligible or relevant to the user. It may rename parameters, combine parameters, set defaults for parameters, and the like.

Multiple inheritance
In a programming language that does not support multiple inheritance of base classes, wrapper functions can be used to simulate it. Below is an example of part of a Java class that "inherits" from LinkedList and HashSet.
pbi casSake ipeet Sak St{ ulc ls tcSt mlmns tc, e
en.wikipedia.org/wiki/Wrapper_f unction 1/3

piaeLneLs sak rvt ikdit tc; piaeHsStst rvt ahe e; pbi boenps(beto { ulc ola uhOjc ) i (e.d() rtr sakps() f stado) eun tc.uho; es rtr fle le eun as; } pbi Ojc pp){ ulc bet o( Ojc o=sakpp) bet tc.o(; strmv() e.eoeo; rtr o eun ; } pbi boencnan(beto { ulc ola otisOjc ) rtr stcnan() eun e.otiso; } }

Programming convenience
Wrapper functions can be used to make writing computer programs easier. An example of this is the MouseAdapter and similar classes in the Java AWT library.[3]

Library functions and system calls


Many library functions, such those in the C Standard Library, act as interfaces for abstraction of system calls. The fork and execve functions Glibc are examples of this. Thay call the lower-level fork and execve system calls, respectively. This may lead to incorrectly using the terms "system call" and "syscall" to refer to higher-level library calls rather than the similarly named system calls, which they wrap.[citation needed]

See also
Adapter pattern Language binding wrapper to another language SWIG automatic wrapper generator

References
1. ^ Reselman, Bob; Peasley, Richard; Pruchniak, Wayne (1998). Using Visual Basic 6 (http://books.google.co.uk/books?id=X5ZQAAAAMAAJ&client=firefox-a&pgis=1) . Que. p. 446. ISBN 0-78971633-X, 9780789716330. http://books.google.co.uk/books?id=X5ZQAAAAMAAJ&client=firefox-a&pgis=1. 2. ^ Stevens, Richard; Fenner, Bill; Rudoff; Andrew M. (2003). UNIX Network Programming (http://books.google.co.uk/books?id=ptSC4LpwGA0C&client=firefox-a) . Addison-Wesley. pp. 56,29. ISBN 013-141155-1, 9780131411555. http://books.google.co.uk/books?id=ptSC4LpwGA0C&client=firefox-a. 3. ^ The Java Tutorials (http://java.sun.com/docs/books/tutorial/uiswing/events/mouselistener.html)

Retrieved from "http://en.wikipedia.org/w/index.php?title=Wrapper_function&oldid=519203592" Categories: Articles with example Java code Subroutines

Wrapper f unction - Wikipedia, the f ree ency clopedia

This page was last modified on 22 October 2012 at 13:56. Text is available under the Creative Commons Attribution-ShareAlike License; additional terms may apply. See Terms of Use for details. Wikipedia is a registered trademark of the Wikimedia Foundation, Inc., a non-profit organization.

en.wikipedia.org/wiki/Wrapper_f unction

3/3

Potrebbero piacerti anche