I have a huge chunk of code that works on say two version of some param , let say ver1 and ver2.
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.
Now, there are different fields that are applicable for ver1 and some for ver2.
So in the code at multiple places i have to do
if(ver1) {
// set fields specific to ver1
}
else {
// set fields specific to ver2
}
I don't like the idea of putting so may if statements in the code, as the code tends to look ugly.
Any alternatives this ?
I was thinking some generic inline / macro definition where a field is set only if flag passed is true ?
Also, on the optimization side , should not be expensive than if else
@edit -- some details of internal organization of code
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.
The version param is passed to each class to decide what field is to be set and which to ignore.