Title: MODELING BEHAVIOR IN STATE MACHINE DIAGRAMS
1MODELING BEHAVIOR IN STATE MACHINE
DIAGRAMS Introduction UML state machine
diagrams depict the various events and states
that an object may be in and the transitions
between those states.
2- Events, States, and Transitions
- An event is a significant or noteworthy
occurrence. For example - A telephone receiver is taken off the hook.
- A state is the condition of an object at a moment
in time-the time between events. For example - A telephone is in the state of being "idle"
after the receiver is placed on the hook and
until it is taken off the hook. - A transition is a relationship between two states
that indicates that when an event occurs, the
object moves from the prior state to the
subsequent state. For example - When the event "off hook" occurs, transition the
telephone from the "idle" to "active" state.
3State Machine Diagrams A UML state machine
diagram, as shown in Figure 29.1, illustrates the
interesting events and states of an object, and
the behavior of an object in reaction to an
event. Transitions are shown as arrows, labeled
with their event. States are shown in rounded
rectangles. It is common to include an initial
pseudo-state, which automatically transitions to
another state when the instance is created.
4(No Transcript)
5A state machine diagram shows the lifecycle of an
object what events it experiences, its
transitions, and the states it is in between
these events. It need not illustrate every
possible event if an event arises that is not
represented in the diagram, the event is ignored
as far as the state machine diagram is concerned.
Therefore, we can create a state machine diagram
that describes the lifecycle of an object at
arbitrarily simple or complex levels of detail,
depending on our needs.
6- Subject of a state machine Diagram
- A state machine diagram may be applied to a
variety of UML elements, including - classes (conceptual or software)
- use cases
- Since an entire "system" may be represented by a
class, it too may have its own state machine
diagram.
7State Machine Diagrams in the UP? There is not
one model in the UP called the "state model."
Rather, any element in any model (Design Model,
Domain Model, and so forth) may have a state
machine to better understand or communicate its
dynamic behavior in response to events. For
example, a state machine diagram associated with
the Sale design class of the Design Model is
itself part of the Design Model.
8Use Case state machine Diagrams A useful
application of state machine diagrams is to
describe the legal sequence of external system
events that are recognized and handled by a
system in the context of a use case. For example
- During the Process Sale use case in the NextGen
POS application, it is not legal to perform the
makeCreditPayment operation until the endSale
event has happened. - During the Process Document use case in a word
processor, it is not legal to perform the
File-Save operation until the File-New or
File-Open event has happened.
9A state machine diagram that depicts the overall
system events and their sequence within a use
case is a kind of use case state machine diagram.
The use case state machine diagram in Figure
29.2 shows a simplified version of the system
events for the Process Sale use case in the POS
application. It illustrates that it is not
legal to generate a makePayment event if an
endSale event has not previously caused the
system to transition to the WaitingForPayment
state.
10(No Transcript)
11Utility of Use Case state machine Diagrams The
number of system events and their legal order for
the Process Sale use case are (so far) relatively
trivial, thus the use of a state machine diagram
to show legal sequence may not seem compelling.
But for a complex use case with myriad system
events-such as when using a word processor-a
state machine diagram that illustrates the legal
order of external events is helpful.
12Classes that Benefit from state machine
Diagrams In addition to state machine diagrams
for use cases or the overall system, they may be
created for virtually any type of class. If an
object always responds the same way to an event,
then it is considered state-independent (or
modeless) with respect to that event. By
contrast, state-dependent objects react
differently to events depending on their state.
Create state machine diagrams for state-dependent
objects with complex behavior.