4 ms·
Encapsulation may hide the data away but it does not hide the effects of state. If an object contains mutable state, it is not referentially transparent. This m
by chongli 13y ago
Encapsulation may hide the data away but it does not hide the effects of state. If an object contains mutable state, it is not referentially transparent. This makes the abstraction leaky, as users need to understand the possible states of an object lest it behave unpredictably.
- adwn 13y ago> If an object contains mutable state, it is not referentially transparent. Why shouldn't an object contain mutable state? When solving a problem for which pure, stateless programming is not suitable, where would you put state if not inside an object?
- chongli 13y agoIn an STM monad, or an ST monad, or even an IORef, or a core.async channel, or whatever. Functional languages have manifold approaches to state that do not require you to lose track of time. And that's the real key to understanding state, isn't it? Time.
- adwn 13y agoPlease do not drag this discussion to stateful vs. stateless programming. It's about OO, which is typically, in practice and in theory, associated with mutable state.
- chongli 13y agoFrom the original article: Refactoring to Functional–Why Class? This is a multi-part series on Refactoring to Functional Programming
- sklivvz1971 13y agoBehavior does not necessarily depend only on state. Behavior depends on state and the code that uses state to implement said behavior. Encapsulation allows us to think on terms of behaviors and not of internal states. That said, this paradigm is easily broken by bad code.