Where and how is the term used by WRAPPER in programming, what does it help?

I meet with software developers who use the term Wrappers to create other classes or APIs or even some codes, this is a term used by experienced programmers

So, any idea what they mean by that;

eg. simple question; we got two types of array sorting methods, create a wrapper for it

The above example is a very simple example.

+63
c #
Jul 20 '10 at 19:44
source share
7 answers

The term "wrapper" is often used. Typically, it is used to describe a class that contains an instance of another class, but which does not directly expose this instance. The main purpose of the shell is to provide a “different” way of using the wrapped object (perhaps the shell provides a simpler interface or adds some functionality).

The word wrapper can also be used to describe classic design patterns.

The flow around an object to provide a simplified interface to it is often described as a Façade pattern. A wrapper is a facade.

Sometimes you may have a class that is suitable for a particular interface, but you cannot change its code to fit that interface. You can create a wrapper for this class that implements the interface, but which directs most calls to the wrapped object. This is the adapter template. The wrapper is an adapter.

An example that you describe where you have two classes that can sort arrays using different algorithms, for example, like the "Strategy" template, where you provide a way to perform operations on an object, but the algorithm used for this operation , may vary depending on the structure of this object.

For example, one of your sorting algorithms may be large for arrays less than 100 in length, but then performance may be a problem for it. Another algorithm may be useful for large arrays. You can create a wrapper for two algorithms that support the sort operation, but decide which algorithm to use based on the length of the array.

The vast majority of shells exist to hide some kind of complexity.

+106
Jul 21 '10 at 17:28
source share

Similar explanation - What is packaging?

Example 1: Ipad wraps Iphone

What does an iPad do, what does an iPhone not do?

Is it not the same thing, except that one screen has more?

The ipad wraps the iphone: it means that you have all the advantages of the iphone inside the ipad itself, and there are advantages of a larger screen, etc. But in fact, inside the ipad lies the Iphone.

What is different then? The only thing that is different is the look: you have a large screen, and you may not be able to make phone calls on the iPad.

An iphone is the only thing inside an Ipad. The Ipad literally wraps the Iphone. Except you can't make calls with an Ipad because the ability to make phone calls have not been "exposed". Apple want you to buy x2 products not just one: P

This is literally the same with "objects."

............. inside there is everything good, which is the same, but a different look. Another wrapper.

"Shells may exhibit other features than the underlying object" ...... well, but what does that mean?

Sometimes a shell can restrict access to things inside. For example, an ipad may limit your ability to make phone calls, even if the Iphone hidden in it has this capability.

Example 2: Automatic machine acting as a wrapper for a manual machine

Think of an automatic machine and a manual machine. Behind the scenes, in an automatic car, there is some kind of engineering mechanism that automatically shifts gears for you, but, in fact, under the surface, the car is still a manual car. In other words, the automatic functions of the car "wrap" the manual functionality of the car. If you wanted to manually shift gears in an automatic machine, you simply cannot do this. The ability to shift gears “not set” in an automatic machine. But it is exposed in a manual car. Of course, the analogy is a little taut, but I hope you understand what I'm getting at.

But what is the purpose of the wrapper?

You would write a wrapping class if you want to simplify things. You would create an easy-to-use wrapper and leave all the complex bits inside the wrapper, ensuring that these complex bits would not be set.

For example, you might have a .net shell that makes COM calls below. If you did not have a wrapper, then you will have to make these COM calls yourself. Fortunately, with the wrapper, you simply make calls to the .net wrapper code, which in turn makes these COM calls. And this, I hope, should simplify things for you.

+53
Jun 30 '16 at 10:22
source share

You just write easy-to-use code to hide the complexity of the code below. This is especially useful when you need to call some low-level API from a higher-level language, and you want to hide all the ugly codes.

Edit: you can find more about this in these two wiki articles: library and function

+9
Jul 20 '10 at 19:45
source share

A Wrapper is code that is created to call an API internally without changing the actual API.

An example of this is the Facebook release of its Facebook CK SDK. The SDK is actually a wrapper because it allows you to call your base platform without providing you with specific methods and classes. The Facebook Developer Toolkit, on the other hand, is a complete API.

+4
Jul 20 '10 at 19:53
source share

There are many examples of “wrappers,” and the term is sometimes used interchangeably. Below are a few examples that come to mind:

DLL Wrapper

In the past, I created the COM wrapper around the .NET DLL to use the advanced .NET features in older applications that understand COM but do not understand .NET.

Object Wrapper (Java)

In Java, there is a class provided in the java.lang to provide object methods for eight primitive types. All primitive shell classes in Java are immutable. Therefore, the Wrapper classes are used to represent primitive values ​​when an Object is required.

+2
Jul 20 '10 at 19:53
source share

Wrapper function, a function whose main purpose is to call the second function

+2
May 05 '14 at 11:56
source share

Say you want to add more functionality to your code, but you cannot change the code. This is where the wrapper helps. You can use the shell to get output without changing the source code.

-one
May 31 '18 at 8:41
source share



All Articles