But come on, having to create getters and setters |
Indeed, but if you try harder then encapsulation is not all about setters and getters only.
You should always write setters and getters, the question is do you really need them for all member variables? and even more importantly do you even need all those variables in the first place?
Instead of avoiding setters and getters, first step is to access restrict member variables into private\protected (and almost never public).
Because by reducing amount of variables you also reduce amount of needed getters\setters.
It's all about how you design your classes, for example, setters and getters should always be inline methods, defined in header (but outside class).
Inline setters and getters should take no more than 2 lines.
Why inline? because you want your cpp file clean, containing only functions that are not setters\getters, that way you forget of having them, main point is cleaner cpp file and secondary benefit is letting compiler inline them if possible which is small performance benefit.
Usually you need much more getters than setters, a lot of setters are sign of bad design, because that's what class function should do, not the user using setters.
----
Bottom line:
1. Limit amount of variables to only those really needed.
2. Limit your getters to minimum to only those variables you directly use in other code.
3. Limit setters to minimum, many setters are bad design.
4. Never access variables directly, ex. public access.
If you hate writing setters and getters reduce them, change design of your classes, but do not remove getters completely.