title: How to factorize code properly?
body: <p>I've a very basic programming question. Imagine I've two functions whose definition is practically the same except that they vary only in an internal binary condition. The rest of the code in both functions is practically the same. </p>
  
  <p>In order to have a readable and easy-to-maintain code, I was wondering whether there's a better solution other than using a bool parameter that selects the operation mode of those functions? Is there any <code>design-pattern</code> for that?</p>
  
  <p>In the code below, I'm illustrating my doubt with two functions named <code>doA()</code> and <code>doB()</code>. The dots (<code>....</code>) correspond to the code that is exactly the same to both functions.
  I created a new <code>doNew()</code> function with an additional boolean parameter to chose the appropriate functionality. However, note that although this is a possible solution, it's still inefficient because of the duplicated code inside the body of both <code>if</code> conditions.</p>
  
  <pre><code>void doA( ..... ){
       .....
       .....
           if(x!=y){
               ....
               ....
               ....
           }
       .....
  }
  
  void doB( ..... ){
       .....
       .....
           if(x==y){
               ....
               ....
               ....
           }
       .....
  }
  
  void doNew( ....., bool selectionMode ){
       .....
       .....
           if(selectionMode == true){
               if(x==y){
                   ....
                   ....
                   ....
               }
           }
           else{
               if(x!=y){
                   ....
                   ....
                   ....
               }
  
           }
       .....
  }
  </code></pre>