In classes, variables often become closed to encapsulation, and restricting variables to a specific area allows better control of errors and fewer errors. This makes sense, since the fewer places to access a variable, the less places an error can occur with this variable.
However, I always see variables made private, and then the getter and setter function used to extract this value (sometimes even a pointer to this variable!). For example, int a is private to prevent public access, but then getA() and setA() allow direct access to them.
So getter functions and setter functions do not ignore its quotient? I mean, private variables with an access function are the same as public variables, only the code to access them changes. (object.variable vs object.getVariable ())
Is there a reason people make private variables with access functions? Are there any advantages over making it publicly available?
I talk about programming in general, but mostly in C languages ββ(e.g. C, C ++, C #, Obj-C).
object oop class encapsulation
fdh
source share