Hacker News new | ask | show | jobs
by zozbot234 1911 days ago
The point of encapsulation is (1) to protect meaningful invariants of the internal state - you care about external modifications because those might break your invariants; (2) to abstract away an object's interface from how the internal state happens to be implemented. Sometimes there are meaningful choices to be had in implementation, and any allowance for "external" modifications basically adds to your object's interface and breaks that abstraction. Both of these can be useful. Concurrent access is yet another issue, of course, and newer languages make it easier to control it.