tags:

views:

82

answers:

4

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

So any idea what do they mean by it;

e.g. a simple question; we got two types of array sorting techniques, lets create a wrapper for it

The above one is a very simple example

+1  A: 

It's just that you write some easy to use code to hide the complexities of the code underneath. It's especially useful when you need to call some low level API from a higher level language and you want to keep all the "ugly" code hidden away.

Edit: You can find more about it in these two wiki articles: library and function

ho1
+2  A: 

Wrapper is when you create some code that internally invokes other API to do some stuff and does not changes the API,

Example:

Recently Facebook realeased the Facebook C# SDK wich it's actually a wrapper since it only let's you call it's underlying platform without giving you specific methods and classes to do stuff while Facebook Developer Toolkit it's a full API

Carlos Muñoz
+1  A: 

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.

0A0D
+2  A: 

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.

Alex Humphrey
oh, got it ... Thank you :)a very detailed answer, solved my wrapper problems there :)
KiNGPiN