4 ms·
Yep! I completely agree, there is nothing object oriented about the example. So why use constructs meant for describing objected oriented code? Though, the f
by munro 12y ago
Yep! I completely agree, there is nothing object oriented about the example. So why use constructs meant for describing objected oriented code? Though, the fact that someone defined a pattern for designing state machines on top of object oriented constructs is interesting, thanks for bringing that up.
The other option is build a model for talking about state machines on top of Python's features (like decorators, meta classes, even coroutines!) than strict OOP to feel more like idiomatic Python, than say Java. And when someone has written the code already, I say why reinvent the wheel! :)
- Too 12y agoClasses are a way to encapsulate state, you don't have to use them together with oo. How else would you describe the example in python without using object oriented constructs? Global variables or passing around a dictionary with all the things set up in init?
- munro 12y agoA distraction from the main point, being: state graphs rock! And deserve a high level way of talking about them in any language of choice, which most languages don't include in the stdlib. So one may have to roll their own/find a library. And that the article confused code that's "difficult to understand" with state graphs being bad. > Classes are a way to encapsulate state, you don't have to use them together with oo. Lexical closures are another way to encapsulate state, modules are another, then there are monads! People have thought of lots of cool ways to encapsulate state. > How else would you describe the example in python without using object oriented constructs? Global variables or passing around a dictionary with all the things set up in init? I would build the example on state graph terminology, instead of on top of Python's class directly. Though, as userbinator pointed out, someone has described an OOP pattern for talking about state graphs [1]. Unfortunately there is no built in way for talking about state graphs in Python. To build that, Python has lots of fun features I can leverage! I wouldn't artificially limit myself. But first I would definitely research if someone has written a good library. [1] http://en.wikipedia.org/wiki/State_pattern http://en.wikipedia.org/wiki/State_pattern