▲ | majormajor 10 months ago | ||||||||||||||||||||||
I don't follow the connection you're making. State machines often are implemented with mutable objects. And one does not need mutable objects to make "modules-> objects with the transitions being method calls". Every method call could return a fresh, immutable object, nothing requires mutation there. I'd see a method like: `TransitionTo(newState)` as a major smell compared to an explicit `TransistionToNewState` and I think OOO can be helpful (hardly required, of course) in that one neat way of streamlining usage of your code is that if you're implementing objects then the object for something in "State A" might not even have "TransitionToStateC" if that's not a valid operation. (No, you don't HAVE to write state machine code that allows you to ask for invalid operations, but it's a common pattern I've seen in real code and in online discussion/blogs/stack overflow.) | |||||||||||||||||||||||
▲ | grumpyprole 10 months ago | parent [-] | ||||||||||||||||||||||
Objects and "method calls" generally implies mutable state to me, but yes the parent was not explicit about this. I assumed mutable (implicit) state was being argued in favour of an explicit state representation. Perhaps I misunderstood. For a state machine, I would expect a function such as: transition : (old_state, event) -> new_state Or if we use immutable objects, and one method per simple event, then something like: transition_event1 : () -> new_state Which I think is similar to what you hace. So I think we are in agreement here. | |||||||||||||||||||||||
|