Assume I have a class containing 3 methods and an attribute. The class is supposed to encode the values in an array called result. So 3 functions are run in order to get the last encoded result that is stored in result.
class A{
public:
int size;
int* result;
A(int si){
size=si;
result=new int[size];
for(int i=0;i<size;i++)
result[i]=5;
}
void func_1(){
for(int i=0;i<size;i++)
result[i]=i+1;
}
void func_2(){
for(int j=0;j<size;j++)
result[j]=j+10;
}
void func_3(){
for(int k=0;k<size;k++)
result[k]=k+4;
}
};
int main(){
A a(10);
a.func_1(); // consider each method as an encoding function (e.g. encryption, randomization, etc)
a.func_2();
a.func_3();
return 0;
}
Here I stored intermediate results in data member array called result.
My question is whether storing intermediate results in an class's attribute and keep updating it is a bad idea? (i.e. violates the class definition)
If it isn't a good idea what would an alternative be?