title: An idiom for a particular refactoring in c++
body: <p>I asked this question :</p>
  
  <p><a href="https://stackoverflow.com/questions/40043292/best-way-to-refactor-class-hierarchy">Best Way to Refactor Class Hierarchy</a></p>
  
  <p>in such a bad way that I was logically forced to accept the perfectly correct answer. My problem is the following :</p>
  
  <p>I have a class <code>CGrandMother</code> having a public method <code>virtual bool Compute()</code> that does</p>
  
  <pre><code>virtual bool Compute()
  {
      return false;
  }
  </code></pre>
  
  <p>From <code>CGrandMother</code> derives publicly <code>CMother</code> which does not implement <code>Compute</code>. Now from <code>CMother</code> derive publicly <code>C1</code> and <code>C2</code> that do implement <code>virtual bool Compute()</code>. Now <code>virtual bool C1::Compute()</code> and <code>virtual bool C2::Compute()</code> respectively do a lot of stuff proper to respectively <code>C1</code> and to <code>C2</code>, but also a lot of identical stuff proper to <code>CMother</code>. Now there's a class <code>CFamily</code> having as member a pointer to <code>CMother</code> and almost everywhere in the code <code>Compute</code> is called through lines of the form</p>
  
  <pre><code>ptrCMother-&gt;Compute();
  </code></pre>
  
  <p>I want to factor out the common stuff related to <code>CMother</code> done in <code>C1</code> and <code>C2</code> so that I wouldn't have to change all those <code>ptrCMother-&gt;Compute();</code>. Of course I can create a member function in <code>CMother</code> doing it, and call the latter in <code>bool C1::Compute()</code> and <code>bool C2::Compute()</code>. But...</p>
  
  <p>In <code>c++</code>, if you have <code>B</code> deriving from <code>A</code>, <code>A::dostuff()</code> and <code>B::dostuff()</code> and if <code>p</code> points to a type <code>B</code> then <code>p-&gt;dostuff()</code> will execute <code>B::dostuff()</code> by polymorphism. I would like to know if there's an idiom/pattern allowing me to achieve this : "<code>p-&gt;dostuff()</code>" will execute "<code>A::dostuff()</code>" or not (according to a <code>bool</code> let's say) and then "<code>B::dostuff()</code>", which does of course not happen in <code>c++</code> for class member functions that are non constructors etc.</p>
  
  <p>To be clear : base method is not called before its corresponding derived method is called by indirection. Is there an idiom/pattern allowing make base method being called (or not, according to a <code>bool</code>) before its corresponding derived method ?</p>