Download presentation
Presentation is loading. Please wait.
Published byKadin Fulwood Modified over 10 years ago
2
StateChart Diagrams
3
State Machines Overview Change summary –core constructs –notation Examples Backward compatibility User benefits Issues
4
Overview State machines specify discrete behavior by mapping received events into sets of states. They may specify detailed behaviors of classes or constrain operational sequences of ports or interfaces. The core constructs in statemachines include: –States, Regions, Transitions, Events Notated using state machine diagrams Typical applications of statemachines include: –object lifecycle states an “order” object might be in –event-driven behaviors of embedded controllers –UI controllers –valid Sequences of calls via interfaces or ports
5
Change Summary for UML 2.0 New core constructs added: –entry/exit points on submachines –state machine specialization/redefinition –state machine Termination –protocol state machines transitions pre/post conditions protocol conformance UML 1.4 core constructs updated: –metamodel refactoring Notational enhancements –action blocks –state lists
6
Entry/Exit Points: Usage VerifyCard OutOfService acceptCard ReleaseCard VerifyTransaction outOfService releaseCard ATM ReadAmount : ReadAmountSM aborted usage of exit point usage of entry point rejectTransaction again invoked submachine
7
Entry/Exit Points: Definition ReadAmountSM selectAmount EnterAmount ok abort aborted amount otherAmount abort again definition of exit point definition of entry point
8
Specialization Redefinition as part of class specialization ATM acceptCard() outOfService() amount() Behaviour Statemachine FlexibleATM otherAmount() rejectTransaction() Behaviour Statemachine >
9
State Machine Redefinition State machine of ATM to be redefined VerifyCard ReadAmount selectAmount acceptCard ReleaseCard VerifyTransaction selectAmount amount outOfService releaseCard OutOfService ATM {final}
10
State Machine Redefinition FlexibleATM redefines ATM VerifyCard ReadAmount selectAmount acceptCard ReleaseCard VerifyTransaction selectAmount amount outOfService releaseCard OutOfService FlexibleATM {final} ATM {extended} EnterAmount ok otherAmount rejectTransaction {extended}
11
State Machine Redefinition FlexibleATM Statemachine States and transitions can be added States and state machines can be extended Regions can be added, and regions can be extended Transitions can be replaced or extended –Actions can be replaced –Guards can be replaced Submachines can be replaced ReadAmount SelectAmount VerifyTransaction EnterAmount ok otherAmount rejectTransaction FlexibleATM ATM {extended}
12
State Machine Specialization Independent state machine specialization –not as part of class specialization –facilitates reuse of behaviours > ATMsm > FlexibleATMsm ATMmachines
13
Protocol State Machines onGround checked flying check() [cleared for take off] takeOff() /[landing rear is retracted] land () postcondition instead of action Equivalent to pre and post conditions added to the related operations: takeOff() Pre -in state "checked" -cleared for take off Post -landing rear is retracted -in state "flying"
14
Example: Notation Enhancements Transition notationState lists Idle Req(Id) MinorReq=Id; MajorReq=Id; [ID<=10] [ID>10] Minor(Id) Major(Id) Busy alternative choice sequence of actions VerifyCard, ReleaseCard Is a notational shorthand for logCard Logged VerifyCard ReleaseCard logCard Logged
15
States example Library Title
16
Backward Compatibility In general all UML 1.4 state machine concepts are preserved in the 2.0 proposal Submachines: stub-states replaced by connection points Specialization (only a note in UML 1.4) now specified Protocol state machines now specified as a separate compliance point
17
User Benefits Entry/Exit Points –reuse via encapsulation of statemachine control interfaces –scalability Specialization –reuse, refinement Protocol State Machines –usage of stat emachines at higher level of abstraction
18
Issues State machines for operations –Currently not supported Is Event metaclass needed for state machines ? –or only part of the runtime model?
20
What Does a Statechart Depict?
21
Classifier of a State Machine The modeling element which is described by the state machine Usually a class
22
State Machines Terms and Concepts State machine is a behavior that specifies the sequences of states an object goes through during its lifetime State Event Transition
23
State Transition Diagrams Show a state machine. Emphasize the event-ordered behavior of an object. Model the changes in an object in response to the environment. Document the following: –Causes of change –Alterations in behavior based on the object’s current condition
24
StateCharts vs. Sequence & Collaboration Diagrams Sequence&Collaboration diagrams show how information passes through the objects of a system over time. State Transition diagrams show how one object changes over time, –given that methods are invoked on it by other objects. Changing the statechart states doesn’t influence the Class structure, i.e. Internal affair
25
States All objects have a “state.” The current state of any object is dictated by the values stored in its attributes. Initial final
26
States A period of time in the life of an object during which it –Satisfies some condition, and/or –Performs some activity, and/or –Waits for some events Some special states –Start state At most one –Final state Can appear many times; all have the same meaning - namely, the classifier ceases to exist
27
States initial and final substates –sequential, concurrent history states
28
States
29
Transitions Event Trigger Guard Condition Action –entry, exit, activity
30
Transitions and Events Example: statechart for Patient class A transition without an explicit event label is called trigerless When source state is complete, transition occurs
31
Events An “event” is the stimulus that prompts an object to make the transition from one state to another. Events take the form of a method call.
32
Events Trigger transitions May represent the receipt of a message: –Between system and actors –Among objects –From an object to itself Several kinds of events –Signals –Calls –Passage of time, for example: after(2 sec) –Change in state, for example: when(quantity < 10) when(date = Y2K)
33
Deferring Events EDo: UG-ban utananezni EDo: UG-ban utananezni
34
Internal Actions/Activities
35
Transition Details Guard Condition Action
36
Self- & Internal- Transitions
37
Actions Triggered by an event An executable, atomic computation Noninterruptible, runs to completion Usually the invocation of an operation (a call) –to the state machine classifier –to objects linked to the classifier
38
Actions vs. Events
39
Composite States EDo: We don’t go deeper now EDo: We don’t go deeper now
40
Sending Messages: Textual Notation
41
Sending Messages: Graphical Notation Syntax: a > dependency drawn from a transition to a class box: the dependency is labeled with the message
42
SuperStates when you have many states that respond to some of the same events in the same way
43
Overriding superstate transitions
44
Hierarchical invocation of Entry and Exit actions
45
Simple Login State Machine
46
Real world example
47
That’s it for today
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.