Finite State Machines and Statecharts
description
Transcript of Finite State Machines and Statecharts
![Page 1: Finite State Machines and Statecharts](https://reader036.fdocuments.in/reader036/viewer/2022062315/56815849550346895dc59f26/html5/thumbnails/1.jpg)
Finite State Machines and Statecharts
Chapter 10Part of Analysis Modeling
Designing Concurrent, Distributed, and Real-Time Applications with UMLHassan Gomaa (2001)
![Page 2: Finite State Machines and Statecharts](https://reader036.fdocuments.in/reader036/viewer/2022062315/56815849550346895dc59f26/html5/thumbnails/2.jpg)
Finite State Machines
• Finite state machines are conceptual machines with a finite number of states.
• State transitions are changes in from one of these states to another.
![Page 3: Finite State Machines and Statecharts](https://reader036.fdocuments.in/reader036/viewer/2022062315/56815849550346895dc59f26/html5/thumbnails/3.jpg)
Finite State Machines (cont)
• State Machines consist of two basic elements:– Events: occurrences at a point in time.– States: recognizable situations that exist over an
interval of time.
• The dynamic aspects of the problem domain are modeled using finite state machines.– Typically one Object encapsulates one state
machine.
![Page 4: Finite State Machines and Statecharts](https://reader036.fdocuments.in/reader036/viewer/2022062315/56815849550346895dc59f26/html5/thumbnails/4.jpg)
Statecharts
• In UML, state machines are represented in Statecharts.
• Statecharts may be flat or hierarchical, and can depict a wealth of information regarding the expected operation of a system.
![Page 5: Finite State Machines and Statecharts](https://reader036.fdocuments.in/reader036/viewer/2022062315/56815849550346895dc59f26/html5/thumbnails/5.jpg)
Statechart Examples
![Page 6: Finite State Machines and Statecharts](https://reader036.fdocuments.in/reader036/viewer/2022062315/56815849550346895dc59f26/html5/thumbnails/6.jpg)
Statechart Examples (cont)
![Page 7: Finite State Machines and Statecharts](https://reader036.fdocuments.in/reader036/viewer/2022062315/56815849550346895dc59f26/html5/thumbnails/7.jpg)
Statechart Examples (cont)
![Page 8: Finite State Machines and Statecharts](https://reader036.fdocuments.in/reader036/viewer/2022062315/56815849550346895dc59f26/html5/thumbnails/8.jpg)
Conditions• Conditions are represented after
an event with square brackets
• Conditions determine which, if any, state the event transitions to.
![Page 9: Finite State Machines and Statecharts](https://reader036.fdocuments.in/reader036/viewer/2022062315/56815849550346895dc59f26/html5/thumbnails/9.jpg)
Actions
• Actions associated with a state transition are shown after the event causing that transition, separated by a “/”.
![Page 10: Finite State Machines and Statecharts](https://reader036.fdocuments.in/reader036/viewer/2022062315/56815849550346895dc59f26/html5/thumbnails/10.jpg)
Too Many Actions Clutter Diagrams
![Page 11: Finite State Machines and Statecharts](https://reader036.fdocuments.in/reader036/viewer/2022062315/56815849550346895dc59f26/html5/thumbnails/11.jpg)
Activities
• Activities actions appear on a states block using the “Do / Activity” notation.– Clean up the event transitions – Prevent unnecessary repetition
![Page 12: Finite State Machines and Statecharts](https://reader036.fdocuments.in/reader036/viewer/2022062315/56815849550346895dc59f26/html5/thumbnails/12.jpg)
Activities Example
![Page 13: Finite State Machines and Statecharts](https://reader036.fdocuments.in/reader036/viewer/2022062315/56815849550346895dc59f26/html5/thumbnails/13.jpg)
Entry and Exit Actions
• Entry and Exit actions occur upon entering or leaving a state.
![Page 14: Finite State Machines and Statecharts](https://reader036.fdocuments.in/reader036/viewer/2022062315/56815849550346895dc59f26/html5/thumbnails/14.jpg)
Entry and Exit Actions (cont)
• Entry and exit actions can also be displayed as activities.
![Page 15: Finite State Machines and Statecharts](https://reader036.fdocuments.in/reader036/viewer/2022062315/56815849550346895dc59f26/html5/thumbnails/15.jpg)
Hierarchical Statecharts
• Hierarchies are used to simplify state charts.– Each sub-state gains the transitions of the super-
state.– Being in the super-state means being in one and
only one of the sub-states.
• Common transitions can be aggregated to the super-state
![Page 16: Finite State Machines and Statecharts](https://reader036.fdocuments.in/reader036/viewer/2022062315/56815849550346895dc59f26/html5/thumbnails/16.jpg)
Hierarchical Statecharts Example
![Page 17: Finite State Machines and Statecharts](https://reader036.fdocuments.in/reader036/viewer/2022062315/56815849550346895dc59f26/html5/thumbnails/17.jpg)
Concurrent Statecharts
• When multiple sub-states must be active simultaneously, a concurrent statechart is used.
![Page 18: Finite State Machines and Statecharts](https://reader036.fdocuments.in/reader036/viewer/2022062315/56815849550346895dc59f26/html5/thumbnails/18.jpg)
Statechart Guidelines
• States must represent identifiable situations or intervals of time.
• Each state should have – A unique name.– An exit.
• On flat statecharts, only one state at a time should be active.
![Page 19: Finite State Machines and Statecharts](https://reader036.fdocuments.in/reader036/viewer/2022062315/56815849550346895dc59f26/html5/thumbnails/19.jpg)
Statechart Guidelines (cont)
• Events and Actions are distinct:– Events are the cause of transitions• Something that happens.
– Actions are the effect of transitions• A command.
• Conditions are boolean values – they must evaluate to “true” or “false”
• Actions, Activities, and Conditions are optional; use only where necessary.
![Page 20: Finite State Machines and Statecharts](https://reader036.fdocuments.in/reader036/viewer/2022062315/56815849550346895dc59f26/html5/thumbnails/20.jpg)
Developing Statecharts from use Cases
1. Collect the actions, conditions and results from a use case description.
2. Develop a preliminary statechart with those actions and conditions as the events and the results and the states.
3. Consider any alternative external events not in the use case.
4. Develop hierarchical and concurrent statecharts as necessary.
![Page 21: Finite State Machines and Statecharts](https://reader036.fdocuments.in/reader036/viewer/2022062315/56815849550346895dc59f26/html5/thumbnails/21.jpg)
Summary
• Finite state machines are used to model the dynamic aspects of the problem domain using statecharts.
• Statecharts consist of Transitions and States– Events cause Transitions (possibly based on a
condition)– Actions or activities are caused by transitions.
• Statecharts may be flat, hierarchical, or concurrent.