wrapper function
TRANSCRIPT
-
7/30/2019 Wrapper Function
1/3
30/12 Wrapper f unct ion - Wikipedia, t he f ree ency c lopedia
wikipedia.org/wiki/W rapper_func tion
Wrapper functionFrom Wikipedia, the free encyclopedia
A wrap per function is a f unction in a comp uter program w hose main purpose is to call a second function [1] withlittle or no additional computation. This is also known as method delegation. Wrapper functions can be used for anumber of purposes.
Contents
1 Adapting class/object interfaces2 Code testing3 Multiple inheritance4 Programming convenience5 Library functions and system calls6 See also7 References
Adapting class/object interfaces
Main article: Adapter pattern
Wrapper fu nctions can be used to adap t an existing class or object to have a different interface. This is especiallyuseful when using existing library c ode.
Code t esting
Wrapper functions can be used to write error checking routines for pre-existing system functions without increasingthe length of a code by a large amount by repeating the same error check for each call to the function. [2] All calls tothe 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 repeate dly, wi th d ifferent 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 beused to simulate it. Below is an example of part of a Java class that "inherits" from LinkedList and HashSet.
pub lic class StackSet implements Stack , Set {
http://en.wikipedia.org/wiki/Programming_languagehttp://en.wikipedia.org/wiki/Programming_languagehttp://en.wikipedia.org/wiki/Multiple_inheritancehttp://en.wikipedia.org/wiki/Wrapper_function#Library_functions_and_system_callshttp://en.wikipedia.org/wiki/Wrapper_function#Programming_conveniencehttp://en.wikipedia.org/wiki/Wrapper_function#Adapting_class.2Fobject_interfaceshttp://en.wikipedia.org/wiki/Function_(computing)http://en.wikipedia.org/wiki/Computer_programhttp://en.wikipedia.org/wiki/Multiple_inheritancehttp://en.wikipedia.org/wiki/Programming_languagehttp://en.wikipedia.org/wiki/Wrapper_function#cite_note-1http://en.wikipedia.org/wiki/Debugginghttp://en.wikipedia.org/wiki/Adapter_patternhttp://en.wikipedia.org/wiki/Wrapper_function#Referenceshttp://en.wikipedia.org/wiki/Wrapper_function#See_alsohttp://en.wikipedia.org/wiki/Wrapper_function#Library_functions_and_system_callshttp://en.wikipedia.org/wiki/Wrapper_function#Programming_conveniencehttp://en.wikipedia.org/wiki/Wrapper_function#Multiple_inheritancehttp://en.wikipedia.org/wiki/Wrapper_function#Code_testinghttp://en.wikipedia.org/wiki/Wrapper_function#Adapting_class.2Fobject_interfaceshttp://en.wikipedia.org/wiki/Delegation_(programming)http://en.wikipedia.org/wiki/Wrapper_function#cite_note-0http://en.wikipedia.org/wiki/Computer_programhttp://en.wikipedia.org/wiki/Function_(computing) -
7/30/2019 Wrapper Function
2/3
pri vat e LinkedList stack ;
pri vat e HashSet set ;
pub lic boo lea n push ( Object o ) { if ( set. add ( o )) return stack. push ( o ) ; else return false ; }
pub lic Object pop () { Object o = stack. pop () ;
set. remove ( o ) ;
return o ; }
pub lic boo lea n contains ( Object o ) { return set. contains ( o ) ; } }
Programming convenience
Wrapper functions can be used to make writing computer programs easier. An example of this is theMouseAdapter 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. Theork 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 patternLanguage binding wrapper to another languageSWIG 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-7897-1633-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 0-13-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
http://en.wikipedia.org/wiki/Special:Categorieshttp://en.wikipedia.org/w/index.php?title=Wrapper_function&oldid=519203592http://java.sun.com/docs/books/tutorial/uiswing/events/mouselistener.htmlhttp://en.wikipedia.org/wiki/Wrapper_function#cite_ref-2http://books.google.co.uk/books?id=ptSC4LpwGA0C&client=firefox-ahttp://en.wikipedia.org/wiki/Special:BookSources/0-13-141155-1,_9780131411555http://en.wikipedia.org/wiki/International_Standard_Book_Numberhttp://books.google.co.uk/books?id=ptSC4LpwGA0C&client=firefox-ahttp://en.wikipedia.org/wiki/Wrapper_function#cite_ref-1http://books.google.co.uk/books?id=X5ZQAAAAMAAJ&client=firefox-a&pgis=1http://en.wikipedia.org/wiki/Special:BookSources/0-7897-1633-X,_9780789716330http://en.wikipedia.org/wiki/International_Standard_Book_Numberhttp://books.google.co.uk/books?id=X5ZQAAAAMAAJ&client=firefox-a&pgis=1http://en.wikipedia.org/wiki/Wrapper_function#cite_ref-0http://en.wikipedia.org/wiki/SWIGhttp://en.wikipedia.org/wiki/Language_bindinghttp://en.wikipedia.org/wiki/Adapter_patternhttp://en.wikipedia.org/wiki/Wikipedia:Citation_neededhttp://en.wikipedia.org/wiki/Execvehttp://en.wikipedia.org/wiki/Fork_(operating_system)http://en.wikipedia.org/wiki/Low-levelhttp://en.wikipedia.org/wiki/Glibchttp://en.wikipedia.org/wiki/System_callhttp://en.wikipedia.org/wiki/Abstraction_(computer_science)http://en.wikipedia.org/wiki/Interface_(computing)http://en.wikipedia.org/wiki/C_Standard_Libraryhttp://en.wikipedia.org/wiki/Standard_libraryhttp://en.wikipedia.org/wiki/Wrapper_function#cite_note-2http://en.wikipedia.org/wiki/Java_AWThttp://en.wikipedia.org/wiki/Category:Subroutineshttp://en.wikipedia.org/wiki/Category:Articles_with_example_Java_code -
7/30/2019 Wrapper Function
3/3
Wrapper function - Wikipedia, the f ree encyclopedia
wikipedia.org/wiki/W rapper_func tion
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.
http://www.wikimediafoundation.org/http://wikimediafoundation.org/wiki/Terms_of_Usehttp://en.wikipedia.org/wiki/Wikipedia:Text_of_Creative_Commons_Attribution-ShareAlike_3.0_Unported_License