I'm in the middle of refactoring a project (in C++11) and I'm struggling with a decision is it good to change huge enum with about 100
record to separate classes.
This enum is used in about 4 places in code in 4 different functions with huge switch statements. For every enum, the record is some code in every function.
I'm thinking about creating an interface and them implement in classes but the number of classes in the project will increase by 100. That's why I'm concerned if this will cost me some performance decrease or will have a huge impact on memory usage or will have other consequences. I know that code will be in better condition but also it's very important that it will work fast (not extremely fast) but it's server application so it's an important factor.
Some code samples:
enum MyEnum {
RECORD_1,
RECORD_2,
...
RECORD_100
}
void doSomething(MyEnum en) {
switch (en) {
case RECORD_1: {
} break;
case RECORD_2: {
} break;
//...
case RECORD_100: {
} break;
};
}
void doSomethingElse(MyEnum en) {
switch (en) {
case RECORD_1: {
} break;
case RECORD_2: {
} break;
//...
case RECORD_100: {
} break;
};
}
So I'm thinking in creating interface:
class AbstractInterface {
public:
virtual void doSomething() = 0;
virtual void doSomethingElse() = 0;
};
And then implemets this interface in classes:
class Record1 : public AbstractInterface {
public:
void doSomething() override;
void doSomethingElse() override;
};
//...
class Record2 : public AbstractInterface {
public:
void doSomething() override;
void doSomethingElse() override;
};
Is it a good way of refactoring this type of code in that way? and not decreasing the performance of the application?