Re:Ask HN: Why do you make class members private?
by robalni on Tuesday July 26, 2022 @02:53AM
(#32235195)
> any references to it are bound to break
Do you mean that if someone changes a class member, they would not change in all places that use that class member? Why not?
> someone that relies on your class may not have access to the code
As I wrote in the clarification, I'm only interested in cases where everyone has access to all the code.
Think of the interface to your class as a contract: this is how this class works, from now until eternity (or until the next breaking change ;) ). Relying on implementation details breaks that contract, the contract is on the interface not on the guts.
It won't be 'hard to change' it may be impossible to change. Because someone that relies on your class may not have access to the code of the other class!