State Pattern

Figure: State Master/Slave

  • The third example demonstrates the usage of a state master and a state slave ports.
  • The state pattern supports a master-slave relationship to selectively activate and deactivate states. An activity can lock a state at the slave to inhibit state changes at critical sections as shown in figure above.
  • A critical section prevents an activity from being interrupted at an unsuitable point of execution. The state pattern gives the master precedence for state changes over the slave.
  • As soon as a request for a state change is received from the master, the slave rejects locks for states that are not compatible to the pending state change of the master. The requested state change of the master is executed by the slave as soon as all locks for states affected by the state change are released.
  • The state pattern is, for example, used by the task monitoring component of the sequencing layer for graceful deactivation of component internal user activities. User provided handlers at the slave allow for cleanup tasks with a state change.
  • Further information can be found in PhD thesis from Prof. Dr. C. Schlegel (on pages 253-254).

Figure: State Pattern