Download State Machines - Software Engineering - Lecture Notes and more Study notes Software Engineering in PDF only on Docsity! 1 State Machines & Advanced State Machines 2 Outline State machines: Introduction State machine diagrams States Transitions Events Advanced state machines: Composite states Simple Orthogonal Submachine states Submachine communication History 5 Introduction There are two types of state machines: Behavioral state machines Protocol state machines State machines are most commonly used to model dynamic behavior of classes In UP, state machines can be used in: requirements, analysis, design A significant challenge is testing state machines: manual walkthrough, simulation, code generation + test harnesses for state machines 6 State machine diagrams There are three main modeling elements in state diagrams: states, transitions, and events. Example of a simple state machine, Fig. 21.2 [Arlow & Neustadt] 7 States Summary of UML state syntax, Fig.21.4 [Arlow & Neustadt 2005] 10 Transitions A junction pseudo-state represents a point where transitions merge or branch, e.g. Fig.21.7 [Arlow & Neustadt 2005] 11 Transitions A junction pseudo-state may have more than one output transition (protected by mutually exclusive guard conditions) e.g. Fig.21.8 [Arlow & Neustadt 2005] 12 Transitions Choice pseudo-state can also be used, e.g. Fig. 21.9 [Arlow & Neustadt 2005] 15 Events A signal is a package of information sent asynchronously between objects. Example of signal event Fig. 21.12 [Arlow & Neustadt 2005] Example of sending a Signal Fig. 21.13 [Arlow & Neustadt 2005] 16 Events Change events are positive edge triggered. Example of a change event, Fig. 21.15 [Arlow & Neustadt 2005] 17 Events Time events are indicated by the keywords when and after. Example of a time event, Fig. 21.16 [Arlow & Neustadt, 2002] 20 Simple composite states A superstate that contains a single region is called a simple composite state, e.g. Fig 22.5 [Arlow & Neustadt 2005] 21 Orthogonal composite states Orthogonal composite states consist of two or more sub-machines that execute in parallel. In Fig 22.6 [Arlow & Neustadt 2005] there are two such composite states, Initializing and Monitoring 22 Orthogonal composite states The composite state Initializing, Fig 22.7 [Arlow & Neustadt 2005] 25 Submachine states Fig. 22. 10 [Arlow & Neustadt 2005]. The notation for a submachine state is <state name : name of referenced state machine diagram> 26 Submachine communication Asynchronous submachine communication can be achieved via attributes: The modeled reactive object has a set of attributes that can be used by submachines The communication mechanism: one machine sets attributes and the other uses the attribute values in guard conditions of their transitions 27 Submachine communication Example of communication via attributes, Fig. 22.11 [A&N 2005]