State Machine Diagrams Chapter 10 Martin Introduction describes
State Machine Diagrams Chapter #10 [Martin]
Introduction • describes the dynamic behavior of objects over time • each object is treated in isolation • describes the events and operations that manipulate the object • one state diagram per class in the class diagram • one logical state diagram may be spread out into one or more physical diagrams for space considerations • enrichment of the finite state machine model
A state diagram consists: • a collection of states of the object under consideration • a collection of actions while entering a state, existing a state or within a state • a collection of transitions between the states of the object • a collection of events that trigger transitions • a collection of conditions (optional) that might constrain the triggering of events, or implementations of transitions
State – a formal definition • is a condition during the life of an object during which the object performs an action or waits for some event • an object after being created must be at one particular state at any instant • unless otherwise mentioned, an object remains in a state for a finite time • UML allows modeling of transient states • states that exist only for a very short and insignificant duration
Event – a formal definition • a noteworthy occurrence • something that happens within the system or interacting with the system at an instant • something that has a significant impact on the system • examples • • • sending a signal or data receiving a signal or data making a request for execution a Boolean condition becoming true a timeout condition becoming true …
Basic Syntax initial State name entry/ … event (params) [guard] / action (params) exit/ … ) s ram a (p t n ve do/ actions event (params) e actions final
Semantics: • Initial pseudostate: • not a state but point to initial state • State: • A condition during the life of an object during which the object performs an action or waits for some event • Transitions: • a movement from one state to another • Rules by which a class change from one state to another state • Has a label : trigger-signature [guard] / activity (cont. to next slide) • Final State: • Indicates that the state machine is completed • Deletion of object
Semantic (cont. ) • Trigger-signature: • A single event that triggers a potential change of state • Guard: • A Boolean condition that must be true for the transition to be taken • Activity • Some behavior must be performed during transition • All parts are optional
Example:
Internal Activity • States can react to events without transitions • Internal activity: • Putting event, guard, and activity inside the state • Entry Activity: • Executes when we enter a state • Exit Activity: • Executes when we exit from a state
Self Transition • A transition that loops back to the same state • Difference from internal activities? • Entry/Exit activities do not perform for internal activities – but for self transition
Case Study 1: Online Shopping - User Account • For the user account to be created, it has to meet some initial requirements. For example, user id (used as a login name) must be unique, at least for the existing accounts. After account was created, it might need to be verified. Verification depends on the company and could include e-mail, phone, and/or address verification. If account was not verified during some predefined period of time, that account could be moved to the suspended accounts. • New, active, or suspended accounts could be cancelled at any time by client's request. • User account might be suspended for security reasons, manually or automatically. For example, website intrusion detection system locks user account for predefined period of time, if there were several unsuccessful login attempts using incorrect account password. After account lock times out, account is activated back automatically. • Some user accounts could be inactive for a long period of time. Company policy or business rules could require moving such dormant for a year or two accounts to the suspended state.
- Slides: 13