I come across software developers using the term of creating Wrappers of other classes or APIs or even some codes, this is a term used by experienced Software Programmers
<The term 'wrapper' gets thrown around a lot. Generally its used to describe a class which contains an instance of another class, but which does not directly expose that instance. The wrapper's main purpose is to provide a 'different' way to use wrapped object (perhaps the wrapper provides a simpler interface, or adds some functionality).
The word 'wrapper' can also be used when describing classic design patterns.
Wrapping an object to provide a simplified interface to it is often described as the 'Facade' pattern. The wrapper is the facade.
Sometimes you may have a class which would suit a specific interface, but you can't change the code for it to make it conform to that interface. You can create a wrapper for that class which implements the interface, but which directs most of the calls to the wrapped object. This is the 'Adapter' pattern. The wrapper is the adapter.
The instance you describe, where you have two classes which can do array sorting using different algorithms sounds like the 'Strategy' pattern, where you provide a way to perform an operation on some object, but the algorithm used for that operation may be different depending upon the structure of that object.
For example, one of your sort algorithms may be great for arrays of length less than 100, but then performance might be an issue for it. The other algorithm might be good for bigger arrays. You can create a 'wrapper' for the two algorithms which supports the sort operation but decides which algorithm to use based on the array length.
The vast majority of wrappers exist to hide some sort of complexity.
Code not used to explain.
What does the ipad do that the iphone doesn't do?
Aren't they basically the same thing, except one has a bigger screen?
The Ipad "wraps" the iphone: meaning that you have all the benefits of the iphone WITHIN the ipad itself, AND have the benefits of a larger screen etc. But fundamentally, inside the ipad, lies an Iphone.
What then is different? The only thing that is different is the exterior: you have a larger screen, and perhaps, you cannot make phone calls on the Ipad.
It's literally the same thing with "objects".
.............the inside has all the good stuff which is the same, but a different exterior. A different wrapper.
"Wrappers may expose different features than the underlying object" ......okay, but what does this mean?
Sometimes the wrapper might limit the things you can access inside. For example, the ipad may limit your ability to make phone calls, even though the Iphone buried within it, has that capability.
Think of an automatic car, and a manual car. Behind the scenes, in an automatic car, there is some engineering mechanism which automatically changes the gears for you, but fundamentally, under the surface, the car is still a manual car. In other words, the automatic features of the car "wraps" the manual functionality of the car. If you wanted to manually change the gears by yourself in an automatic car - you simply can't do it. The ability to change gears "is not exposed" in the automatic car. But it is exposed in a manual car. Granted the analogy is a little strained, but I hope you see what I'm getting at.
You'd write a wrapping class if you wanted to simplify things. You'd create an easy to use 'wrapper' and leave all the complicated bits inside the wrapper, ensuring that those complicated bits are not 'exposed'.
For example, you could have a .net wrapper, which underneath, makes COM calls. If you didn't have a wrapper, then you'd be forced to make those COM calls yourself. Luckily with the wrapper, you'd just make the calls to the .net wrapping code - which would in turn make those COM calls. And that should hopefully simplify things for you.
Wrapper function, a function whose main purpose is to call a second function
Say you want to add some more functionalities to your code but you cannot change the code. That's where wrapper helps. You can use a wrapper to get the output without changing the original code.
There are many examples of "wrappers" and the term is sometimes used interchangeably. Following are a couple examples that come to mind:
DLL Wrapper
In the past I have created a COM wrapper around a .NET DLL in order to use the advanced features of .NET in older applications which understand COM but do not understand .NET.
Object Wrapper (Java)
In Java, there is a class provided in the java.lang
package to provide object methods for the eight primitive types. All of the primitive wrapper classes in Java are immutable. So Wrapper
classes are used to represent primitive values when an Object
is required.
A Wrapper is some code that is created to internally call some API without changing the actual API.
An Example of this is Facebook's release of their Facebook C# SDK. The SDK is actually a wrapper since it only lets you call its underlying platform without giving you specific methods and classes. On the other hand, Facebook Developer Toolkit is its full API.