3 ms·
I'm interested in this, since I thought the concept of encapsulation is maintaining, and hiding, state inside of an object. What's the difference between mutati
by nomel 6y ago
I'm interested in this, since I thought the concept of encapsulation is maintaining, and hiding, state inside of an object. What's the difference between mutating state on the inside and hiding state on the inside? Aren't they practically the same?
- willtim 6y ago> What's the difference between mutating state on the inside and hiding state on the inside? Aren't they practically the same? You can mutate state on the inside, but still provide a "pure" mathematical function on the outside. For example, a root finding solver. The general problem/feature with objects, is that when a method returns, the object may be in a different state (and often is). Such state changes are hidden but not "encapsulated" as they still contribute to the global state of your application. In other words, the global variables are still there, you've just organised them into modules.