State Pattern - should a state know about its context?
- by Extrakun
I am referring to the state pattern as described in this link.
In the example class diagram, a context has numerous states. However, it does not show how does a state communicates with a context (perhaps an input in a state has impact on a setting in the context).
The two examples on the page shows either passing the context to the state via a function, or storing a reference to the context. Are those advisable?
Are there other ways for a state to communicate with a context?
Update to an edit:
For instance, I am doing a remote control which can have several states. Say, the context has a setting for Volume, and I am in one of the states which allow me to tweak the volume. How should the state communicates with the context that the volume is being changed?