title: Implement a workchain with templatemethod pattern?
body: <p>I have a hierarchy of <code>worker</code> classes, all of which do some kind of processing to a workpiece. The idea is, that each worker does some pre processing, pushes the workpiece to the subclass and then does some postprocessing:</p>
  
  <pre><code>public void process(Workpiece wp) {
     doPreprocessing(wp);
     sub.process(wp); // this obviously doesn't work
     doPostProcessing(wp);
  }
  </code></pre>
  
  <p>Right now I'm solving this by declaring new abstract methods:</p>
  
  <pre><code>public final void process(Workpiece wp) {
     doPreprocessing(wp);
     subProcess(wp); // this obviously doesn't work
     doPostProcessing(wp);
  }
  
  protected abstract void subProcess(Workpiece wp);
  </code></pre>
  
  <p>which has the obvious disadvantage that for each hierarchy-level, there is an additional, new method. </p>
  
  <p>I would like to guarantee, that all pre- and post-process methods are executed even with new, user-implemented workers, which are not under my control. </p>
  
  <p>How would you do that?</p>