Possible Duplicate:
Why use getters and setters?
It seems to me like a major hassle to write accessor and mutator methods, particularly when dealing with very simple attributes. Why should I bother using them?
Possible Duplicate:
Why use getters and setters?
It seems to me like a major hassle to write accessor and mutator methods, particularly when dealing with very simple attributes. Why should I bother using them?
The answer mainly depends on what are you writing code for and how much you trust yourself if working alone:
friend
directive that allows fine grain encapsulation without the bother of having setters and getters (even if it encourages coupling so there are two different schools of thinking here)I can't speak to the C++ syntax burden but in general object oriented terms you should supply getters and setters because other classes have no business knowing how you store your internal state, including which properties are directly stored, which are computed based on other state and which are devolved further to other objects. Making a contractual announcement with the wider world about how a class will store state will limit the adjustments you can make in the future, often inhibiting optimisation and breaking your code as the problem you're solving becomes more nuanced.