Sunday, August 29, 2010

Wrapper Class

A wrapper class is any class which "wraps" or "encapsulates" the functionality of another class or component. class that "wraps" the functionality of another class or API in a simpler or merely different API.



Examples:-


public class Wrapper
{

private int x = 10;
private int y = 20;
public Wrapper()
{
// TODO: Add constructor logic here
}
public int add(int x, int y)
{
Wrapper.inside obj = new inside();
//core functionality of this method is written in the wrapped class.
int sum = obj.add(x, y);
return sum;
}

//The below class is wrapped by the wrapper class. we can access only inside this class. Outside the class, we cant access this class.

private class inside
{
public int add(int x, int y)
{
return x + y;
}
}//inside class of wrapper end here.

}// WRAPPER Class ends here


Sample wrapper class for Excel Functionality.

Wrapper class for excel functionality is very common, in almost all 3rd party grid, they use a grid to excel converter using the wrapper class/ adapter class

For more details :- http://www.tanguay.info/web/index.php?pg=codeExamples&id=389

No comments: