So I have the following class which I find silly and would like to refactor.
class Data
{
public:
bool getVariableA();
bool getVariableB();
bool getVariableC();
void setVariableA();
void setVariableB();
void setVariableC();
private:
bool A;
bool B;
bool C;
}
This goes on for like 100 variables and growing, most of which are boolean. If you were to refactor this class (while keeping all the data in it instead of spreading out), how would you go about it?
Issues with the current structure are at least that it's a) too much code b) pain to add stuff c) unit testing coverage always needs to be added manually when growing the class.
how would you go about it?
The solution proposed by @JohnHenly is spot-on:
I would use this code:
std::vector<bool> data;
enum index { var_a, var_b, var_c, ... };
data[var_a] = true;
If possible though, consider also splitting the data by one of these criteria:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With