UML State Diagrams State Diagrams State Diagrams are
- Slides: 11
UML State Diagrams
State Diagrams • State Diagrams are used to model the behavior of an individual object across its entire lifetime (i. e. , across all use cases that it participates in)
State Diagrams • A State Diagram shows – The different states that an object can be in – The events that cause the object to change states – The actions performed by the object when it changes state • Basically just a finite state machine with some fancy features
State Diagrams • Any class may have a State Diagram that describes the behavior of its instances • Only create State Diagrams for classes that exhibit interesting "stateful" behavior – Object's current behavior depends on its past in nontrivial ways • State Diagrams contain: – States – Transitions
States • A state is a situation during the life of an object during which it satisfies some condition, performs some activity, or waits for some event • Example: Thermostat
Transitions • A transition is a relationship between two states indicating that an object in the first state will perform certain actions and enter the second state when a specified event occurs and specified conditions are satisfied
Transitions • Event – Message received or passage of time • Guard – Boolean expression that determines whether transition is enabled • Action – Executable, atomic computation performed when transition is taken – Send message, create object, etc.
Transitions • Example: Thermostat
Transitions • Example: Alarm. Clock
Initial / Final states • Example: Thermostat
Advanced Features • State Diagrams have many advanced features that are not discussed here