SysML: How to Use State Diagrams to Model Systems Behavior
10-12 minutes
A state machine diagram (also known as state chart, state transition diagram or state diagram) is a kind of behavior diagram; like an activity diagram and a sequence diagram, it presents a dynamic view of a system. Unlike an activity diagram and a sequence diagram, a state machine diagram focuses attention on how a structure within a system(object, or block instance) changes state in response to event occurrences over time.
A state machine diagram is well suited to serve as detailed design of a particular classifier(that is, an input into development). Like a sequence diagram, a state machine diagram is a precise and unambiguous specification of behavior. Thus, it is often be used for system design and simulation/code generation.
Why State Machine Diagrams?
State machine diagrams typically are used to describe state-dependent behavior for an object. An object responds differently to the same event depending on what state it is in. State machine diagrams are usually applied to objects but can be applied to any element that has behavior to other entities such as actors, use cases, methods, subsystems systems, etc. and they are typically used in conjunction with interaction diagrams(usually sequence diagrams).
For example:
Consider you have $100,000 in a bank account. The behavior of the withdraw function would be: balance:= balance – withdraw Amount; provided that the balance after the withdrawal is not less than $0; this is true regardless of how many times you have withdrawn money from the bank. In such situations, the withdrawals do not affect the abstraction of the attribute values, and hence the gross behavior of the object remains unchanged.
However, if the account balance would become negative after a withdrawal, the behavior of the withdraw function would be quite different. This is because the state of the bank account is changed from positive to negative; in technical jargon, a transition from the positive state to the negative state is fired.
The abstraction of the attribute value is a property of the system, rather than a globally applicable rule. For example, if the bank changes the business rule to allow the bank balance to be overdrawn by 2000 dollars, the state of the bank account will be redefined with condition that the balance after withdrawal must not be less than $2000 in deficit.
What is a State?
James Rumbaugh (the 3 Amigos of UML) defines that:
“A state is an abstraction of the attribute values and links of an object. Sets of values are grouped into a state according to properties that affect the gross behavior of the object.”
State Notation
State
A state is a constraint or a situation in the life cycle of an object, in which a constraint holds, the object executes an activity or waits for an event.
A state machine diagram is a graph consisting of:
- States (simple states or composite states)
- State transitions connecting the states
Example:
Characteristics of State
- State represents the conditions of objects at certain points in time.
- Objects (or Systems) can be viewed as moving from state to state
- A point in the lifecycle of a model element that satisfies some condition, where some particular action is being performed or where some event waits