title: Alternative to multiple use of if-else in the code base
body: <p>I have a huge chunk of code that works on say two version of some param , let say ver1 and ver2.</p>
  
  <p>Version is a run time field and i intend to keep it as, so that i don't have to build the code with different flags and same lib files can be used for both versions.</p>
  
  <p>Now, there are different fields that are applicable for ver1 and some for ver2.</p>
  
  <p>So in the code at multiple places i have to do </p>
  
  <pre><code>if(ver1) {
      // set fields specific to ver1
  }
  else {
      // set fields specific to ver2
  }
  </code></pre>
  
  <p>I don't like the idea of putting so may if statements in the code, as the code tends to look ugly.</p>
  
  <p>Any alternatives this ?</p>
  
  <p>I was thinking some generic inline / macro definition where a field is set only if flag passed is true ?</p>
  
  <p>Also, on the optimization side , should not be expensive than if else</p>
  
  <p>@edit -- some details of internal organization of code</p>
  
  <p>Can't post the details of code. But one important matter of fact is that its a huge legacy code which needs upgrade with backward compatibility. </p>
  
  <p>The version param is passed to each class to decide what field is to be set and which to ignore.</p>