3 ms·
> What matters is that users of this class cannot, in a separate module/class, directly access those three fields. Yes that's what private does, it makes sure
by robalni 4y ago
> What matters is that users of this class cannot, in a separate module/class, directly access those three fields.
Yes that's what private does, it makes sure that you can't access something from any place in the code. The questions is why you should make this constraint.
> That's invalid code
Is private used to tell programmers that if you change this variable or call this function, the object can be in an invalid state?
> For some reason you left the name array in place
Is the reason here that private makes it easier to find all uses of something because it reduces the number of places you have to look in? Example, you change the meaning of a variable but forget to change the name so the compiler will not tell you about all the places to change. You can still change all the uses of that member in the class because those uses are easy to find and know about.