Wrapper Class

A wrapper class is any class which “wraps” or “encapsulates” the functionality of another class or component. This provides a level of abstraction from the implementation of the underlying class and “hides” the implementation from the outside world.

Example:
I have a class for TAX calculation containing method to calculate TAX, and my another class called SALARY calculator is there. Now to calculate salary I want to use TAX calculator class. And my interest is that I will not disclose to other class “How I am calculating TAX”?. Then I will simply wrap my TAX calculator class by SALARY class.

namespace BlogProject
{

class Wrapper //Wrapper Class
{
class InnerClass //Inner Class
{
public Int32 ProcessData(int Val)
{
return Val + 1;
}
}

public Int32 CallRapper()
{
Wrapper.InnerClass wpr = new Wrapper.InnerClass(); // Internally call to Wrapper class.
return wpr.ProcessData(100);
}
}

class Program
{
static void Main(string[] args)
{
Wrapper w = new Wrapper();
Console.WriteLine(“Data Process by inner class and show by Wrapper Class:-” + w.CallRapper());
Console.ReadLine();
}
}
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s