Beginning in every introductory programming class, we are taught to use accessors and setters as opposed to exposing the inner-workings of a class. Students learn the point of the exercise for a later day, but now I understand that such practice (A) prevents the implementation from becoming part of the contractual exported API, (B) improves encapsulation and data-hiding, and (C) allows a guarantee as to whether certain operations should happen (increase a counter, log something, etc.) whenever a variable is set or accessed.
How about using getter/setters from within the instance itself? For example,
class A {
private:
int number = 43;
public:
int getNumber();
void setNumber(int);
};
When it comes down to it, does this really matter? Are there any guidelines we can follow, or has there been anything written on this scenario? This question comes up a lot in my mind when I am programming, but I have never seen anybody discuss accessors/mutators with regards to the instance itself.
Thank you!