Explanation of wrapper class

  • Thread starter Thread starter source_acct
  • Start date Start date
<[email protected]> a écrit dans le message de (e-mail address removed)...

| Can someone explain the function of a wrapper class and maybe an
| example? Thanks.

The Wrapper pattern is also known as the Adapter patern and this is
basically what it does; adapt one class to another purpose.

One of many useful ideas for using the Wrapper pattern is when you want to
extend a class that only has non-virtual methods :

public class NonVirtual
{
public void DoSomething()
{
...
}
}

public class VirtualAdapter
{
private NonVirtual realObject = new NonVirtual();

public virtual void DoSomething()
{
realObject.DoSomething();
}
}

Now DoSomething() can be polymorhically overridden in derived classes.

Joanna
 
Back
Top