I have a serious problem with application which i working on. It has a lot of procedural code and now it needs to refactoring now.. The problem: we have two different application in general, but they're use the same "module", concrete functions from this module. It looks like this: (pseudocode)
// general application
class App1 {
DoSomething();
}
class App2 {
DoSomething();
}
// "module":
a;
b;
c;
function DoSomething {
if (App1) {
// working with a, b here
}
if (App2) {
// working with a, c here
}
}
Note that "DoSomething" function gets "a", "b", "c" from outside. Also, this "DoSomething" may call another function inside itself, "DoSomething 2" for example..
This if statements aka "if App1 then, else if it App2 then.." scattered by the all the code, and it becomes the problem. Furthermore, count of this Application will may increase in the future (
What a better way to resolve this problem? Please, can you give an advice, what patterns/approaches may helps here?
UPDATE
This is real examples from the code, but all names was replaced with fake names:
situation one - "helpers.js"
import { isApp1 } from '../../..';
import { constTypes } from '../../../../someAnotherHelpers';
import { constSybtypes } from '../../someAnotherHelpersTwo';
const App1Constants = {
[constTypes.a]: { .. },
[constTypes.b]: {
[constSybtypes.b.a]: 33,
},
};
const App2Constants = {
[constTypes.c]: 22,
};
const getConstants = isApp1()
? App1Constants
: App2Constants;
situation two - "some react class"
import { isApp1 } ...;
class Test {
const className = isApp1 ? 'object_app1' : 'object_app2';
render() {
<div className={className}>
...
</div>
}
}
situation three - "selector.js" (used everywhere..)
import { isApp1 } ...;
import { someAnotherSelector } from '.';
import { someAnotherSelector2 } from '../../../anotherSelectors';
export const someSelector =
isApp1()
? (state) => {
return someAnotherSelector(state.someReducer.variant1);
}
: (state) => {
return someAnotherSelector2(state.someReducer.variant2);
}
};