This is probably a really bad question, but I occasionally have parts of code that look exactly like this. And every time I write it, I'm wondering why I bother.
class Car
{
private:
int Color;
public:
const int GetColor() const { return Color; }
void SetColor(int c) { Color = c; }
};
Would it not be easier to just
class Car
{
private:
...
public:
int Color;
}
I know some members need an interface for validation, or conversions, or may not even need to be writable at all. But is that why I pretend to make things like this Color variable private, even though it really isn't? To be consistent? So that I don't have 10 private member variables and 4 public? Even though the ton of pointless interface functions makes my class even harder to write, manage, and understand?