|
|
|
|
|
by na85
1970 days ago
|
|
>In an OO program all state is global, because you can't understand any given object's behaviour without knowing what its state is and what the behaviours of all the objects it communicates with are, and you can't understand those without knowing their states either. By that logic all state in any program is global. But if I'm writing an MMO server my GoldCoin class doesn't need to know about the client's connection state. Have you actually written or worked with OO code before? Your comment reads like you have not. |
|
All state in any program is global in the sense of being reachable from top-level. You can, and should, make your state hierarchical - reachable from top-level should not mean reachable from anywhere, you can have (non-toplevel) parts of your program that only access parts of your state. Unfortunately OO is uniquely bad at this, because objects are encouraged to have hidden coupling.
> But if I'm writing an MMO server my GoldCoin class doesn't need to know about the client's connection state.
But you have no way of knowing or enforcing that. "You wanted a banana but what you got was a gorilla holding the banana and the entire jungle" - your GoldCoin might contain a ("encapsulated" i.e. hidden) reference to another class that has a reference to another class and so on, and so eventually it does depend on the client's connection state.
> Have you actually written or worked with OO code before?
Yes, for many years, which is why I've become an advocate of FP style instead.