Sei sulla pagina 1di 4

Information Systems Analysis and Design CSC340 Information Systems Analysis and Design CSC340

XI. State and Activity Diagrams State Diagrams (Statecharts)


n These are state transition diagrams (with some interesting
State Diagrams additions) which can be used to describe the operating
Events and States environment of the system, interactions of the system with that
environment, also the lifetime of some object (a person, a
Superstates
student,…) within the system.
Activity Diagrams
n Transitions are supposed to represent actions which occur
Petri Nets “quickly” and are not interruptible. A transition can have an
associated triple
Event[Condition]/Action
all parts of this triple are optional.
n States are supposed to represent longer-running activities (or
other things). What constitutes “quickly” and “longer-running”
depends on the application.

© 2002 Jaelson Castro and John Mylopoulos Statechart Diagrams -- 1 © 2001 Jaelson Castro and John Mylopoulos State and Activity Diagrams -- 2

Information Systems Analysis and Design CSC340 Information Systems Analysis and Design CSC340

State Diagram for Purchase Order Events


condition
n An event is a happening that the system needs to know about.
n For example, completing an assignment, failing an exam, or a
/get order system crash are all events.
Checking [all items in stock] Dispatching n An event may trigger an action by an actor or the system being
Do/check items Do/package items
developed.
n In UML, there are four types of events:
start
ü Change events occur when a condition becomes true, e.g.,
[some item not when(balance < 0);
action /deliver
event In stock] ü Signal events designate the receipt of an explicit (real-time)
package
Item received
signal from one object or actor to another;
Item received [all items in stock] ü Call events indicate the receipt of a call for an operation by
[some item not an object or actor;
In stock] ü Time events mark the passage of a designated period of
Waiting Delivered time, e.g., after(10 seconds)

© 2001 Jaelson Castro and John Mylopoulos State and Activity Diagrams -- 3 © 2001 Jaelson Castro and John Mylopoulos State and Activity Diagrams -- 4

Information Systems Analysis and Design CSC340 Information Systems Analysis and Design CSC340

Course Lifetimes States


n A state represents a time period during which
ü A predicate is true, e.g., budget - expenses >0,
Initialization
ü An action is being performed, e.g., check inventory for order items,
or
offerNewCourse
ü Someone waits for an event to happen, e.g., arrival of a missing
/set count=0;create(CourseRoster)
order item.
addStudent[count<10] n A state can be “on” or “off”.
[count=10] n When a state is “on”, all its outgoing transitions are eligible to fire. For
Open Closed a transition to fire, its event must occur and its condition must be true.
When a transition does fire, its action is carried out.
cancel quarterStarted n States can have associated activities. Special activity constructs
cancel include:
end state ü do/stateDiagramName(parameterList) -- “calls” another state
[Lochovsky98] diagram;
Cancelled ü entry/action -- carry out the action when entering the activity;
/delete(CourseRoster)
ü exit/action -- carry out the action when exiting;

© 2001 Jaelson Castro and John Mylopoulos State and Activity Diagrams -- 5 © 2001 Jaelson Castro and John Mylopoulos State and Activity Diagrams -- 6

1
Information Systems Analysis and Design CSC340 Information Systems Analysis and Design CSC340

Course Lifetimes, Again


Superstates
Initialization
do / Initialize n State transition diagrams can be very hard to read once they
grow to more than a few dozen states.
addStudent/
count=0;CourseRoster.Create() n For UML state diagrams, states can be composed into nested
states, or superstates. Such compositions make it possible to
addStudent[count<10]
Open view a state diagram at different levels of abstraction.
entry/RegisterStudent n A superstate consists of one or more states.
exit/CourseRoster.AddStudent(student)
n When an AND superstate is “on”, all its states are also “on”.
[count=10] n When an OR superstate is “on”, one of its states is “on”.
cancel

Cancelled cancel Closed


do/FinalizeCourse

CourseRoster.Delete()
quarterStarted

© 2001 Jaelson Castro and John Mylopoulos State and Activity Diagrams -- 7 © 2001 Jaelson Castro and John Mylopoulos State and Activity Diagrams -- 8

Information Systems Analysis and Design CSC340 Information Systems Analysis and Design CSC340

An OR Superstate …More on Transmission

Transmission
Transmission

select R
Neutral Reverse
select R select N
Neutral Reverse
select N
select N select F
select N select F

Forward

Forward stop upshift upshift


First Second Third
downshift downshift

© 2001 Jaelson Castro and John Mylopoulos State and Activity Diagrams -- 9 © 2001 Jaelson Castro and John Mylopoulos State and Activity Diagrams -- 10

Information Systems Analysis and Design CSC340 Information Systems Analysis and Design CSC340

State Diagram for Purchase Order


Order Processing as an AND Superstate
/get order Checking [all items in stock] Dispatching
Do/check items Do/package items
Waiting Cancelled
[some item not
Item received
In stock]
[some item not Item received
Checking Dispatching In stock] [all items in stock] /deliver
package
Waiting
Delivered

Authorizing Authorized /cancel


OR
Superstate
Rejected Delivered
Cancelled

© 2001 Jaelson Castro and John Mylopoulos State and Activity Diagrams -- 11 © 2001 Jaelson Castro and John Mylopoulos State and Activity Diagrams -- 12

2
Information Systems Analysis and Design CSC340 Information Systems Analysis and Design CSC340

Auto Transmission
Bridge Vulnerability Rules
Ignition
turn key to start
Playing Bridge Rubber [Transmission release
N-S vulnerability in Neutral] key
Off Starting On
turn key off
Not N-S game N-S game
Vulnerable N-S wins turn key off
vulnerable
Transmission

select R
Neutral Reverse
E-W vulnerability select N
select N select F

E-W game E-W game Forward


Not
Vulnerable E-W wins stop upshift upshift
vulnerable
First Second Third
downshift downshift

© 2001 Jaelson Castro and John Mylopoulos State and Activity Diagrams -- 13 © 2001 Jaelson Castro and John Mylopoulos State and Activity Diagrams -- 14

Information Systems Analysis and Design CSC340 Information Systems Analysis and Design CSC340

Activity Diagrams
Firing a Transition in Activity Diagrams
n Activity diagrams describe activities which involve concurrency
and synchronization. n Activity diagrams use a Perti net-like notation to describe activities
which involve concurrency and synchronization.
n Activity diagrams are a variation of state diagrams that focuses
on the flow of actions and events. n Petri nets use transitions which involve several input and output
states:
n Can be used
ü To model a human task (a business process, for instance).
ü To describe a system function that is represented by a use
case.
ü In operation specifications, to describe the logic of an
operation. Before After

© 2001 Jaelson Castro and John Mylopoulos State and Activity Diagrams -- 15 © 2001 Jaelson Castro and John Mylopoulos State and Activity Diagrams -- 16

Information Systems Analysis and Design CSC340 Information Systems Analysis and Design CSC340

An Example Order Processing


Receive
Order

for each line


* item on order
[failed] Authorize Check
Payment Line Item

Cancel [in stock]


Order
Assign to
[succeeded] Order

[need to
[stock assigned to reorder]
all line items and
payment authorized] Dispatch Reorder
Order Item

© 2001 Jaelson Castro and John Mylopoulos State and Activity Diagrams -- 17 © 2001 Jaelson Castro and John Mylopoulos State and Activity Diagrams -- 18

3
Information Systems Analysis and Design CSC340 Information Systems Analysis and Design CSC340

Swimlanes
Decision Points in Activity Diagrams
Finance Order Stock
n Decision points: Receive Processing Manager
Order

Calculate [cost<$50] Charge * for each line


customer’s item on order Receive
total cost account Supply
Check Choose
Line Outstanding
Authorize [failed] Order Items
Payment Item
[cost≥$50] Get
authorization *for each chosen
[succeeded] Cancel [in stock] order item
Order
n Dead ends: there may be transitions in an activity diagram with Assign to Assign Goods
Order to Order
no destination state; this can mean that:
ü Not all processing has been specified, [stock assigned to [need to [all outstanding
ü Or, that another activity diagram will take over. all line items and
payment authorized]
reorder] order items filled]

Dispatch Reorder Add Remainder


Order Item to Stock

© 2001 Jaelson Castro and John Mylopoulos State and Activity Diagrams -- 19 © 2001 Jaelson Castro and John Mylopoulos State and Activity Diagrams -- 20

Information Systems Analysis and Design CSC340 Information Systems Analysis and Design CSC340

When to Use What? Additional Readings


n Sequence and collaboration diagrams are useful for modeling n [Booch99] Booch, G. et al., The Unified Modeling Language
interactions; several of them can be used to model dialog User Guide, Chapters 19, 20, 21, 24. Addison-Wesley.
structure for a user interface, or a business process. n [Fowler00] Fowler, M., UML Distilled: A Brief Guide to the
n State diagrams are good for modeling the lifetime of an object or Standard Object Modelling Language, Chapters 8, 9. Addison-
actor, also for modeling user interfaces and business processes Wesley.
which involve many states.
n Activity diagrams are good for modeling business processes and
system processes which involve a lot of concurrency.

© 2001 Jaelson Castro and John Mylopoulos State and Activity Diagrams -- 21 © 2001 Jaelson Castro and John Mylopoulos State and Activity Diagrams -- 22

Potrebbero piacerti anche