P
P
pwN112014-05-13 11:15:33
WPF
pwN11, 2014-05-13 11:15:33

How, using the Wapper (Decorator/Wrapper) pattern, to inherit a sealed class?

There is a PathFigureCollection class, it is sealed, I need to inherit it using Wrapper.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
stringer, 2014-05-13
@pwN11

It is sealed for this, so that it is not inherited. Wrapper is not a way to inherit. You can completely reproduce the class interface on the wrapper (even better if PathFigureCollection has a declared interface - implement it) and use this wrapper instead of PathFigureCollection.
Something like this:

public class PathFigureCollectionWrapper
{
  private PathFigureCollection _pfc;

  public PathFigureCollectionWrapper(PathFigureCollection pfc)
  {
    _pfc = pfc;
  }

  public int Method()
  {
    return _pfc.Method();
  }
}

the desired wrapper methods simply contain calls to the wrapped class instance.
Resharper, by the way, generates wrappers in one click.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question