Wrapper function
A wrapper function is a subroutine in a software library or a computer program whose main purpose is to call a second subroutine[1] or a system call with little or no additional computation.
Purpose
Wrapper functions are a means of delegation and can be used for a number of purposes.
Programming convenience
Wrapper functions can be used to antagonist make writing computer programs easier. An example of this is the MouseAdapter
and similar classes in the Java AWT library.[2]
Wrapper functions are useful in the development of applications that use third-party library functions. A wrapper can be written for each of the third party functions and used in the native application. In case the third party functions change or are updated, only the wrappers in the native application need to be modified as opposed to changing all instances of third party functions in the native application.
Adapting class/object interfaces
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.<ref>{{cite book |title=UNIX Network Programming |last=Stevens |first=Richard |author2=Fenner, Bill |author3=Rudoff |author4= Andrew ay 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.
Library functions and system calls
Many library functions, such as those in the C Standard Library, act as interfaces for abstraction of system calls. The fork and execve functions in glibc are examples of this. They call the lower-level [[Fork (operating
References
- ^ Reselman, Bob; Peasley, Richard; Pruchniak, Wayne (1998). Using Visual Basic 6. Que. p. 446. ISBN 9780789716330.
- ^ The Java Tutorials