News for hackers. Stuff that matters.
Re:Ask HN: Why do you make class members private? by dragonwriter on Wednesday July 27, 2022 @04:29PM (#32256448)
> is private a way to tell the programmer to look at all member functions to see if there is already a function that does what you need?

Private is a way of excluding the member so designated from any consideration at all by a consumer of the class. Assuming that they see it at all (which if it is in a compiled library using normal tooling they might well not at all), they are effectively told to treat it as if it does not exist.

There may exist mechanism to bypass this (especially in dynamic languages and/or those with robust introspection/metaprogramming), but that's breaking the warranty seal on the class.

All the functionality that a class provides to consumers is provided by its public members. That's what public members are.

There are no comments on this comment yet.