While reviewing rather old code I found some strange design decision:
// irrelevant stuff removed
class Class {
public:
int GetStage() const { return stage; }
void SetStage( int value ) { stage = value; }
private:
int stage;
};
void ProgressStage( Class* object )
{
int stage = object->GetStage();
assert( stage < MaxStage );
stage++;
object->SetStage( stage );
}
now ProgressStage()
is in the same header because it has to be visible at multiple call sites. It calls non-static member functions of the class. IMO it should be a member function instead:
void Class::ProgressStage()
{
//directly access member variables
assert( stage < MaxStage );
++stage;
}
What could be the reason for preferring the former design to the latter?