Hacker News new | ask | show | jobs
by ianp 5685 days ago
Private members are generally just to protect your from yourself. If you have an integer that should /always/ be 1-10, it's easier to use a private variable and a setter that ensures the variable is always valid, than to hope all your code follows the rules. (Then also if the rule changes, e.g. to 5-100, you just need to change one function).

There are some other uses and examples, but this is the simplest one i can think of off the top of my head.