๐Ÿ”„ Lecture 08 ยท State Machine Diagrams

UML State Diagrams

ุงู„ู€ Class diagram = structure. ูˆุงู„ู€ Sequence diagram = interaction between objects. ุฃู…ุง ุงู„ู€ State diagram = behavior of one object over time โ€” ูŠุนู†ูŠ ุฅุฒุงูŠ ุงู„ู€ object ุจูŠุชู†ู‚ู„ ู…ู† state ู„ู€ state. ู…ู‡ู… ููŠ Question 2 (2 marks ููŠ Winter 2025ุŒ ูˆ 4 marks ููŠ Winter 2023).

8
Chapters
3
Event Types
5
Worked Examples
8
Practice Qs
01

What is a State Diagram?

3 ุฃุณุงู…ูŠ ู„ู†ูุณ ุงู„ู€ diagram: State Diagram = State Machine Diagram = Statechart.

๐Ÿ“– Definition

ุงู„ู€ State diagram ุจูŠูˆุตู ุงู„ู€ behavior ุจุชุงุน:

  • A whole systemุŒ ุฃูˆ
  • Some part of a systemุŒ ุฃูˆ
  • An individual object (ุงู„ุฃูƒุชุฑ ุดูŠูˆุนุงู‹).

๐Ÿ”‘ ุงู„ููƒุฑุฉ ุงู„ุฃุณุงุณูŠุฉ

  • ููŠ ุฃูŠ point in timeุŒ ุงู„ู†ุธุงู…/ุงู„ู€ object ุจูŠูƒูˆู† ููŠ state ู…ุนูŠู†.
  • ูƒูˆู†ู‡ ููŠ state ูŠุนู†ูŠ ุฃู†ู‡ ู‡ูŠุชุตุฑู ุจุดูƒู„ ู…ุญุฏุฏ ุฑุฏู‹ุง ุนู„ู‰ ุงู„ู€ events.
  • ุจุนุถ ุงู„ู€ events ุจุชุณุจุจ change of state (transition).
  • ููŠ ุงู„ู€ state ุงู„ุฌุฏูŠุฏุŒ ุงู„ู€ behavior ุจูŠูƒูˆู† ู…ุฎุชู„ู.
๐Ÿงฎ ุงู„ู€ Formal View

State diagram = directed graph:

  • Nodes = states (ุงู„ุญุงู„ุงุช)
  • Arcs (edges) = transitions (ุงู„ุงู†ุชู‚ุงู„ุงุช)
๐Ÿ’ก ุงู„ูุฑู‚ ุงู„ู…ู‡ู… ุนู† ุงู„ู€ Sequence diagramุงู„ู€ Sequence = ุฅุฒุงูŠ objects ูƒุชูŠุฑุฉ ุจุชุชูุงุนู„ ู„ุชู†ููŠุฐ use case. ุงู„ู€ State = ุญูŠุงุฉ object ูˆุงุญุฏ ุจู…ุฑูˆุฑ ุงู„ุฒู…ู†. ุงู„ุงุชู†ูŠู† dynamic ุจุณ ุจุฒุงูˆูŠุฉ ู…ุฎุชู„ูุฉ.
02

Basic Elements โ€” ุงู„ุฑู…ูˆุฒ ุงู„ุฃุณุงุณูŠุฉ

5 ุฑู…ูˆุฒ ู„ุงุฒู… ุชุนุฑูู‡ู….

๐ŸŽจ ุงู„ุฑู…ูˆุฒ ุงู„ู€ 5
StateName
State
Rounded rectangle ู…ุน ุงุณู… ุงู„ู€ state
Initial State
Solid black circle โ€” ุงู„ุจุฏุงูŠุฉ
Final / End State
Black circle ู…ุญุงุทุฉ ุจู€ ring โ€” ุงู„ู†ู‡ุงูŠุฉ
โ”โ”โ–ถ
Transition
Arrow ู…ู† state ู„ู€ state
event [guard] / action
Label
Event ุจูŠุนู…ู„ trigger ู„ู„ู€ transition
โŒฝ
Self-Transition
Arrow ู…ู† state ู„ู†ูุณู‡ุง
๐Ÿ’ก ุงูŠู‡ ูŠุนู†ูŠ "State"ุŸ
  • State = a set of values for the attributes of the given object.
  • ุงู„ู€ object ุจูŠูุถู„ ููŠ ุงู„ู€ state ุฏู‡ ู„ุญุฏ ู…ุง event ูŠุญุตู„ ูˆูŠุณุจุจ transition.

ู…ุซุงู„: Traffic Light โ€” ุงู„ู€ attributes ู…ู…ูƒู† ุชูƒูˆู†: color = "red", activeForSeconds = 0. ู„ูˆ ุงู„ู€ color attribute ุงุชุบูŠุฑ ู„ู€ "green"ุŒ ูŠุจู‚ู‰ ุงู„ู€ state ุงุชุบูŠุฑ.

03

Transitions & Events

Transition = change of state. ูˆุงู„ู€ Event = ุงู„ู„ูŠ ุจูŠุณุจุจ ุงู„ู€ transition.

โžก๏ธ Transition

ุงู„ู€ Transition ุจูŠู…ุซู„ ุชุบูŠูŠุฑ ููŠ ุงู„ู€ state ุฑุฏู‹ุง ุนู„ู‰ event. ุงู„ู€ label ุนู„ู‰ ุงู„ู€ transition ุจูŠูˆุตู:

  1. ุงู„ู€ Event (ุงู„ุฃู‡ู…).
  2. [Guard] (ุดุฑุท ุงุฎุชูŠุงุฑูŠ).
  3. / Action (action ุงุฎุชูŠุงุฑูŠ).
event(parameters) [guard] / action

ู…ุซุงู„: requestToRegister(student) [classSize < max] / createRegistration

๐Ÿ“ž Mini Example โ€” Telephone
idle
off-hook
dial tone
โ“˜ off-hook = event ยท idle, dial tone = states ยท โ”โ”โ–ถ = transition
04

3 Event Types โญ

External ยท Internal ยท Temporal. ุงู„ุฏูƒุชูˆุฑ ุจูŠุญุจ ูŠุณุฃู„ ุนู† ุงู„ูุฑู‚.

๐ŸŒ External Event

= System Event

ุณุจุจู‡ ุญุงุฌุฉ ุจุฑู‘ู‡ ุงู„ู€ system boundary.

ู…ุซุงู„: ุงู„ู€ Cashier ุจูŠุถุบุท ุฒุฑ enter item ุนู„ู‰ POS terminal.

๐Ÿ”ง Internal Event

ุณุจุจู‡ ุญุงุฌุฉ ุฌูˆู‘ู‡ ุงู„ู€ system boundary.

Operation invoked via message ู…ู† object ุชุงู†ูŠ ุฏุงุฎู„ูŠ.

ู…ุซุงู„: Object ุจูŠุณุชุฏุนูŠ method ุนู„ู‰ object ุชุงู†ูŠ โ€” ููŠู†ุชุฌ ุนู†ู‡ event.

โฐ Temporal Event

ุณุจุจู‡ occurrence of a specific date/time ุฃูˆ passage of time.

ุงู„ู€ syntax: after(30s) ุฃูˆ at(midnight).

ู…ุซุงู„: Red light โ†’ Green light ุจุนุฏ 30s.

๐Ÿ“Œ ู…ู„ุญูˆุธุฉุงู„ู€ Temporal events ุจุชุชูƒุชุจ ุจู€ after(...) ู„ู„ู€ duration ุฃูˆ at(...) ู„ู€ specific time. ุดุงุฆุนุฉ ููŠ ุงู„ู€ state diagrams.
05

Activities vs Actions โญ

ุงู„ูุฑู‚ ุงู„ู…ู‡ู…: Action = instantaneous. ูˆ Activity = takes time.

โšก Action

Takes NO noticeable time (instantaneous)

ุงู„ู€ Action ุจูŠุญุตู„ ููŠ 3 ุญุงู„ุงุช:

  • On transition โ€” ู…ุน ุงู„ุงู†ุชู‚ุงู„ ู†ูุณู‡
  • On entry โ€” ู„ู…ุง ู†ุฏุฎู„ state ู…ุนูŠู†
  • On exit โ€” ู„ู…ุง ู†ุฎุฑุฌ ู…ู† state ู…ุนูŠู†

ุฃู…ุซู„ุฉ: readCard, ejectCard, startMotor, stopMotor

Syntax: entry / actionName
Or: exit / actionName

๐Ÿƒ Activity

Takes a period of time (ongoing)

ุงู„ู€ Activity ุจูŠุญุตู„ while in state:

  • ุจูŠุงุฎุฏ ูุชุฑุฉ ุฒู…ู†ูŠุฉ ู…ู„ุญูˆุธุฉ
  • ู…ู…ูƒู† ุงู„ู€ system ูŠุฎุฑุฌ ู…ู† ุงู„ู€ state ู„ู…ุง ูŠุฎู„ุต ุงู„ู€ activity (completion)
  • ุฃูˆ ูŠุฎุฑุฌ ู„ูˆ event ุขุฎุฑ ูŠู‚ุทุนู‡ุง (interruption โ€” early exit)

ุฃู…ุซู„ุฉ: play music, play dial tone, download file

Syntax: do / activityName

๐Ÿ“ Concrete Example โ€” ATM
Serving Customer entry / readCard exit / ejectCard do / process transaction
  • ุงู„ู€ entry / readCard = action ุจุชุญุตู„ ู…ุฑุฉ ูˆุงุญุฏุฉ ู„ู…ุง ู†ุฏุฎู„ ุงู„ู€ state.
  • ุงู„ู€ do / process transaction = activity ุจุชุดุชุบู„ ุทูˆู„ ู…ุง ุฅุญู†ุง ููŠ ุงู„ู€ state.
  • ุงู„ู€ exit / ejectCard = action ุจุชุญุตู„ ู„ู…ุง ู†ุฎุฑุฌ ู…ู† ุงู„ู€ state.
06

Guards & Conditional Transitions

Guard = ุดุฑุท ุจูˆู„ูŠุงู† ู„ุงุฒู… ูŠูƒูˆู† true ุนุดุงู† ุงู„ู€ transition ุชุญุตู„.

๐Ÿ”’ Guard Syntax
event [boolean expression] / action

ุงู„ู€ guard ุจูŠุชูƒุชุจ ุจูŠู† [ ]. ู„ูˆ ุงู„ู€ event ุญุตู„ ุจุณ ุงู„ู€ guard ู…ุด trueุŒ ูุงู„ู€ transition ู…ุง ุจุชุญุตู„ุด.

ู…ุซุงู„: Course Registration

OpenNotEnoughStudents
[classSize โ‰ฅ minimum]
OpenEnoughStudents
ู„ูˆ classSize โ‰ฅ minimum = trueุŒ ูุงู„ู€ transition ุจุชุญุตู„. ู„ูˆ falseุŒ ูุงู„ู€ state ู…ุง ูŠุชุบูŠุฑุด.
โš™๏ธ Self-Transitions with Guards

ุงู„ู€ State diagram ู…ู…ูƒู† ูŠูƒูˆู† ููŠู‡ transition ู…ู† state ู„ู†ูุณู‡ุง. ุฏู‡ ู…ููŠุฏ ู„ู…ุง ู†ุญุชุงุฌ ู†ุนู…ู„ action ุจุฏูˆู† ุชุบูŠูŠุฑ state.

ู…ุซุงู„: requestToRegister(student) / createRegistration โ€” self-transition ุจู€ action. ุงู„ู€ state ูŠูุถู„ OpenNotEnoughStudents ุจุณ createRegistration ุจูŠุชุนู…ู„.

07

Nested / Composite States

State ุฌูˆู‘ู‡ state. ู…ููŠุฏ ู„ุชู†ุธูŠู… ุงู„ู€ complexity ููŠ ุงู„ู€ diagram.

๐Ÿช† Composite State (Substate)

ุงู„ู€ Composite state ุจูŠุญุชูˆูŠ ุนู„ู‰ substates ุฏุงุฎู„ู‡. ุดูƒู„ู‡ ู…ุณุชุทูŠู„ ุฃูƒุจุฑ ููŠู‡ states ุฃุตุบุฑ ุฌูˆู‘ุงู‡.

ุงู„ููˆุงุฆุฏ:

  • ุชู†ุธูŠู… โ€” ุจุชู‚ู„ู„ ุนุฏุฏ ุงู„ู€ transitions ุงู„ุธุงู‡ุฑุฉ ููŠ ุงู„ู€ diagram.
  • ุงู„ู€ outer state ุจุชู†ุทุจู‚ ุนู„ู‰ ูƒู„ ุงู„ู€ substates (ู…ุซู„ุงู‹: exit ู…ู† ุฃูŠ substate = exit from composite).
  • Easier reading and maintenance.

ู…ุซุงู„: ATM โ€” Serving Customer composite

Serving Customer
entry / readCard ยท exit / ejectCard
โ†’ Authenticate โ†’ Select Trans. โ†’ Transaction โ†’

ุงู„ู€ outer transitions (ู…ุซู„ุงู‹ cancel) ุจุชุดุชุบู„ ู…ู† ุฃูŠ substate ุฏุงุฎู„ Serving Customer. ู…ููŠุด ุฏุงุนูŠ ู†ุถูŠู cancel arrow ู…ู† ูƒู„ substate ู„ูˆุญุฏู‡.

๐Ÿ’ก ู…ุชู‰ ู†ุณุชุฎุฏู… composite statesุŸู„ู…ุง ุนู†ุฏูƒ ู…ุฌู…ูˆุนุฉ ู…ู† ุงู„ู€ states ู„ูŠู‡ุง common behavior (ู…ุซู„ุงู‹ ูƒู„ู‡ู… ู…ู…ูƒู† ูŠุชู„ุบูˆุง ุจู€ cancel) ุฃูˆ ุจุชู†ุชู…ูŠ ู„ู†ูุณ ุงู„ู€ logical phase (ู…ุซู„ phases of serving customer).
08

5 Worked Examples

ุฃู…ุซู„ุฉ ูƒุงู…ู„ุฉ ู…ู† ุงู„ุณู„ุงูŠุฏุฒ: Tic-Tac-Toe ยท Traffic Light ยท Garage Door ยท Online Chess ยท ATM.

๐ŸŽฎ Tic-Tac-Toe Game

โ†’
XTurn
XPlays
OTurn
Final states: XWin ยท OWin ยท Tie

Transitions with guards:

  • XTurn โ†’ XWin [XPlays & 3 X's in a row]
  • XTurn โ†’ Tie [XPlays & Board Full & Not 3 X's]
  • OTurn โ†’ OWin [OPlays & 3 O's]

๐Ÿšฆ Traffic Light (Temporal Events)

RedLight
after(30s)
GreenLight
after(25s)
YellowLight
YellowLight โ†’ RedLight [after(5s)] โ€” ูŠูƒู…ู„ ุงู„ุฏูˆุฑุฉ

ูƒู„ ุงู„ู€ transitions ุจุชุณุชุฎุฏู… temporal events (after(...)). ู…ููŠุด external triggers.

๐Ÿšช Automatic Garage Door (Actions)

Closed entry / stop motor
โ†• pressButton โ†•
Opening entry / run motor forwards
โ†“ openingCompleted
Open entry / stop motor
โ†“ pressButton
Closing entry / run motor in reverse
โ†“ closingCompleted โ†’ Closed

ูƒู„ state ุนู†ุฏู‡ entry action ุจู€ stop motor ุฃูˆ run motor. ุงู„ู€ pressButton ู…ู…ูƒู† ูŠู‚ุงุทุน (interrupt) ุงู„ู€ opening ูˆูŠู†ู‚ู„ู‡ ู„ู€ closing.

โ™Ÿ๏ธ Online Chess (UI Screens)

Enter
Welcome
New Account
Standings
Play
Results

Transitions: Welcome โ†’ New Account [Create New Account], Welcome โ†’ Standings [Login], Standings โ†’ Play [Choose Opponent], Play โ†’ Results [Finish Game], Results โ†’ Standings [Continue].

ุฏูŠ state diagram ู„ู€ UI flow โ€” ุจู†ุดูˆูู‡ุง ููŠ ุงู„ู€ apps.

๐Ÿง ATM (Composite States)

ุฃูƒุซุฑ example ู…ุนู‚ุฏ. ููŠู‡ composite state ู„ู„ู€ Serving Customer.

  • Off โ†’ Self Test [turn on / startup]
  • Self Test โ†’ Idle (success)
  • Idle โ†’ Serving Customer [cardInserted]
  • Inside Serving Customer (composite): Authenticate โ†’ Selecting โ†’ Transaction โ†’ end
  • Serving Customer โ†’ Idle [cancel]
  • Idle โ†’ Maintenance [service]
  • Maintenance โ†’ Out of Service [failure]
  • Out of Service โ†’ Off [turn off / shutDown]
๐Ÿ’ก Composite Patternุงู„ู€ Serving Customer composite ุจุชุญุชูˆูŠ substates ู„ู„ู€ authentication flow. ู„ูˆ ุญุตู„ cancel ู…ู† ุฃูŠ substateุŒ ูุงู„ู€ ATM ูŠุฑุฌุน ู„ู€ Idle. ุฏู‡ ุงุณุชุฎุฏุงู… ู†ุธูŠู ู„ู„ู€ composite.
๐ŸŽฏ

Practice Quiz โ€” Lecture 8

8 ุฃุณุฆู„ุฉ ุนู„ู‰ State Diagrams. Question 2 ู…ู† ูƒู„ ุงู…ุชุญุงู† ููŠู‡ 2-4 marks ุนู„ู‰ state diagram.

Question 1 Practice โ€” concept
A state diagram describes the behavior of:
A Multiple interacting objects over time
B An individual object (or a system) over time
C Static structure of the system
D Use case relationships
โœ… ุงู„ุฅุฌุงุจุฉ ุงู„ุตุญ: B โ€” Individual object / system State diagram = behavior of one object (ุฃูˆ one system as a whole) ุนุจุฑ ุงู„ุฒู…ู†.
A โ€” ุฏู‡ ุงู„ู€ Sequence diagram (multiple objects). ยท C โ€” ุฏู‡ ุงู„ู€ Class diagram. ยท D โ€” ุฏู‡ ุงู„ู€ Use Case diagram.
Question 2 Practice โ€” events
A traffic light changes after 30 seconds. What type of event is this?
A External Event
B Internal Event
C Temporal Event
D Composite Event
โœ… ุงู„ุฅุฌุงุจุฉ ุงู„ุตุญ: C โ€” Temporal Event after(30s) = passage of time = Temporal event.
A (External) โ€” ู„ู…ุง ุงู„ู€ trigger ู…ู† ุจุฑู‘ู‡ (ู…ุซู„ user click). ยท B (Internal) โ€” ู…ู† object ุฏุงุฎู„ูŠ. ยท D (Composite) โ€” ู…ููŠุด composite eventุ› ุงู„ู€ composite ุจูŠูƒูˆู† ู„ู„ู€ states.
Question 3 Practice โ€” action vs activity
Inside a state box, you see do / play music. This is:
A An activity (takes time)
B An entry action
C An exit action
D A guard condition
โœ… ุงู„ุฅุฌุงุจุฉ ุงู„ุตุญ: A โ€” Activity ุงู„ู€ keyword do / ูŠุฏู„ ุนู„ู‰ activity (ongoing). ุงู„ู€ play music ุจูŠุงุฎุฏ ูุชุฑุฉ.
B โ€” Entry action syntax: entry / actionName. ยท C โ€” Exit action syntax: exit / actionName. ยท D โ€” ุงู„ู€ Guards ุจุชูƒูˆู† ุจูŠู† [ ].
Question 4 Practice โ€” transition syntax
Given the transition label buy(item) [funds >= price] / debitAccount, what does [funds >= price] represent?
A An event
B An action
C A state name
D A guard condition
โœ… ุงู„ุฅุฌุงุจุฉ ุงู„ุตุญ: D โ€” Guard ุงู„ู„ูŠ ุจูŠู† [ ] = guard (boolean expression). ู„ูˆ true โ†’ ุงู„ู€ transition ุชุญุตู„.
A (event) โ€” ู‡ูˆ buy(item) ู‚ุจู„ ุงู„ู€ guard. ยท B (action) โ€” debitAccount ุจุนุฏ ุงู„ู€ /. ยท C โ€” ู…ุด state name.
Question 5 Practice โ€” symbols
What represents the start state in a state diagram?
A A circle with a ring around it
B A solid black circle
C A rounded rectangle with "start" inside
D A diamond shape
โœ… ุงู„ุฅุฌุงุจุฉ ุงู„ุตุญ: B โ€” Solid black circle ุงู„ู€ Initial state = filled black circle.
A โ€” ู‡ูˆ ุงู„ู€ end state (black circle ู…ุญุงุทุฉ ุจู€ ring). ยท C โ€” ุงู„ู€ regular states ุจุชูƒูˆู† rounded rectangles ูˆู…ุนุงู‡ุง ุงู„ุงุณู…ุŒ ู…ุด ูƒู„ู…ุฉ start. ยท D โ€” ุงู„ู€ Diamond ุฏู‡ ููŠ activity diagrams (decision).
Question 6 Practice โ€” composite
An ATM diagram shows a composite state called ServingCustomer with substates inside, and a cancel transition from ServingCustomer to Idle. What does this mean?
A Cancel only works in the first substate
B Cancel works only when there are no substates
C Cancel works from any substate inside ServingCustomer
D Cancel is forbidden inside the composite
โœ… ุงู„ุฅุฌุงุจุฉ ุงู„ุตุญ: C โ€” From any substate ุงู„ู€ Transition ู…ู† ุงู„ู€ outer boundary ู„ู„ู€ composite ุจุชุดุชุบู„ ู…ู† ุฃูŠ substate ุฌูˆู‘ุงู‡ุง. ุฏูŠ ุงู„ูุงุฆุฏุฉ ุงู„ุฃุณุงุณูŠุฉ ู„ู„ู€ composite states.
A, B, D โ€” ูƒู„ู‡ู… ุจูŠู†ุงู‚ุถูˆุง ููƒุฑุฉ ุงู„ู€ composite states.
Question 7 Practice โ€” when used
When is a state diagram the most useful kind of UML diagram?
A When modeling many objects interacting
B When modeling code structure
C When modeling an object/system with distinct states and transitions between them
D When listing all user actions
โœ… ุงู„ุฅุฌุงุจุฉ ุงู„ุตุญ: C ุงู„ู€ State diagram ุจูŠุจู‚ู‰ ู…ููŠุฏ ู„ู…ุง ุนู†ุฏูƒ object/system ููŠ ุญุงู„ุงุช ู…ุฎุชู„ูุฉ (modes)ุŒ ูˆู…ุนุงู‡ events ุจุชุณุจุจ transitions. ุฃู…ุซู„ุฉ: ATM, Order lifecycle, Door, Game.
A โ€” ุฏู‡ sequence diagram. ยท B โ€” ุฏู‡ class diagram. ยท D โ€” ุฏู‡ use case diagram.
Question 8 Practice โ€” comprehensive
An Order in an e-commerce site has states: Placed โ†’ Paid โ†’ Shipped โ†’ Delivered. The customer can Cancel from any state before Shipped. Which UML element best represents this?
A Cancel transitions from each state separately to a Cancelled state
B A composite state grouping Placed+Paid, with a single Cancel transition from the composite to Cancelled
C A guard condition on the Shipped state
D Mark Cancelled as the initial state
โœ… ุงู„ุฅุฌุงุจุฉ ุงู„ุตุญ: B โ€” Composite state ุงู„ุทุฑูŠู‚ุฉ ุงู„ุฃู†ุธู: composite state ูŠุดู…ู„ Placed ูˆ PaidุŒ ูˆุงู„ู€ Cancel ูŠุทู„ุน ู…ู† ุงู„ู€ composite boundary. ุฏู‡ ุจูŠู‚ู„ู„ ุนุฏุฏ ุงู„ู€ arrows ูˆุจูŠุนูƒุณ ุงู„ู€ logical grouping (orders ุงู„ู„ูŠ ู…ู…ูƒู† ุชุชู„ุบู‰).
A โ€” ูŠุดุชุบู„ุŒ ู„ูƒู†ู‡ ุจูŠู„ุฎุจุท ุงู„ู€ diagram. ุงู„ู€ composite ุฃู†ุธู. ยท C โ€” Guard ุนู„ู‰ state ุบูŠุฑ ู…ู†ุทู‚ูŠ ู‡ู†ุง. ยท D โ€” Cancelled ู„ุงุฒู… ูŠูƒูˆู† final stateุŒ ู…ุด initial.
๐Ÿ“‹

Cheat Sheet

ูƒู„ ุงู„ุฑู…ูˆุฒ ูˆุงู„ู€ syntax ูˆุงู„ู…ุตุทู„ุญุงุช.

๐ŸŽจ Symbols

โ—
Initial state (solid black circle)
โŠ™
Final state (black circle + ring)
Rounded rect
State (with name inside)
โ”โ”โ–ถ
Transition (arrow)
Big rect โŠƒ rects
Composite state with substates

๐Ÿ“ Transition Label Syntax

event
name of event (mandatory)
event(params)
event with parameters
[guard]
boolean condition (optional)
/ action
action to perform (optional)
after(t)
temporal event syntax

โšก Action vs Activity

Action
Instantaneous (no time)
entry / x
Action on entering state
exit / x
Action on exiting state
/ x (on transition)
Action during transition
do / x
Activity (ongoing, takes time)

๐Ÿ“ข 3 Event Types

External
From outside system (button click)
Internal
From inside (object โ†’ object)
Temporal
after(t) or at(time)

๐Ÿ†š Diagram Differences

Class Diagram
Static structure
Use Case Diagram
User-system interactions (high level)
Sequence Diagram
Multi-object dynamic flow
State Diagram
Single object/system behavior over time

โœ… Question 2 Checklist (State part)

1.
Initial state (โ—) + Final state(s)
2.
All meaningful states identified
3.
Each transition has event label
4.
Guards [in brackets] where needed
5.
Use composite for grouped behavior
6.
Use after(t) for time triggers
โšก

Rapid Revision

Flashcards ยท Common Mistakes ยท What the doctor loves.

3 ุฃุณู…ุงุก ู„ู„ู€ State DiagramุŸ
tap
State Diagram ยท State Machine ยท Statechart
3 Event TypesุŸ
tap
External ยท Internal ยท Temporal
Action vs ActivityุŸ
tap
Action = instant ยท Activity = takes time (do /)
Initial state symbolุŸ
tap
โ— Solid black circle
Final state symbolุŸ
tap
โŠ™ Black circle with ring
Transition label syntaxุŸ
tap
event(params) [guard] / action
Temporal event syntaxุŸ
tap
after(30s) ยท at(midnight)
Composite state โ€” ุงูŠู‡ ูุงูŠุฏุชู‡ุŸ
tap
Group substates with common transitions (e.g., cancel from any)
State diagram describesุŸ
tap
Behavior of one object/system over time
Self-transition ุงูŠู‡ุŸ
tap
Arrow ู…ู† state ู„ู†ูุณู‡ุง (e.g., for actions)

๐Ÿšจ Common Mistakes

1. ุฎู„ุท Action ูˆ ActivityAction = instantaneous (entry/exit/on-transition). ูˆ Activity = takes time (do /). ุงู„ู€ do / ุจูŠุฏู„ ุฏุงูŠู…ุงู‹ ุนู„ู‰ activity.
2. ู†ุณูŠุงู† Initial State ุฃูˆ Final StateุฃูŠ state diagram ู„ุงุฒู… ูŠุจุฏุฃ ุจู€ โ— initial state. ู„ูˆ ููŠู‡ ู†ู‡ุงูŠุฉ ู„ู„ู€ behaviorุŒ ุญุท โŠ™ final state.
3. ู†ุณูŠุงู† labels ุนู„ู‰ ุงู„ู€ transitionsูƒู„ transition ู„ุงุฒู… ู„ู‡ุง label (event). ุจุฏูˆู† eventุŒ ุงู„ู€ transition ู…ุง ุชุญุตู„ุด ุจุดูƒู„ ู…ูู‡ูˆู….
4. ุฎู„ุท State Diagram ูˆ Sequence DiagramState = behavior of ONE object over time. ูˆ Sequence = interaction between MANY objects. ู„ูˆ ุงู„ุณุคุงู„ ุนู† ุฅุฒุงูŠ objects ุจุชุชูƒู„ู…ุŒ ุฏู‡ Sequence. ู„ูˆ ุนู† ุฅุฒุงูŠ ุงู„ู€ status ุจูŠุชุบูŠุฑุŒ ุฏู‡ State.
5. ุนุฏู… ุงุณุชุฎุฏุงู… composite statesู„ู…ุง ุนู†ุฏูƒ transition ู…ุดุชุฑูƒ ู…ู† ูƒุฐุง state (ู…ุซู„ cancel ู…ู† ุฃูŠ state)ุŒ ุงุณุชุฎุฏู… composite. ุบูŠุฑ ูƒุฏู‡ ุงู„ู€ diagram ู‡ูŠุจู‚ู‰ cluttered ุจุฃุณู‡ู… ูƒุชูŠุฑุฉ.

โญ What Dr. El-Ramly Loves

๐Ÿ”ฅ ุงู„ุฃุณุฆู„ุฉ ุงู„ู…ุชูƒุฑุฑุฉ ุนู„ู‰ Lec 8
  1. Question 2 (2-4 marks) โ€” ุจูŠุฏูŠ object ู…ุซู„ Message, Order, Booking ูˆูŠุทู„ุจ state diagram. ุฑูƒุฒ ุนู„ู‰ Initial โ†’ states โ†’ Final + transitions ู…ุน events.
  2. Message states (Winter 2025): Received โ†’ Read โ†’ Deleted โ†’ Purged.
  3. Order states (Winter 2023): Placed โ†’ Pdf Valid โ†’ Confirmed โ†’ Processing โ†’ ShippedุŒ ู…ุน Cancelled ูƒู€ alternate path.
  4. Composite states โ€” ู„ู„ู€ flows ุงู„ู„ูŠ ููŠู‡ุง grouped behaviors.
  5. Guards โ€” ู„ู…ุง ุงู„ู€ transition ู…ุดุฑูˆุทุฉ (e.g., classSize โ‰ฅ minimum).
๐ŸŽฏ ู†ุตูŠุญุฉู„ู…ุง ุชุฑุณู… state diagram ููŠ ุงู„ุงู…ุชุญุงู†: ุงุจุฏุฃ ุจู‚ุงุฆู…ุฉ ุงู„ู€ statesุŒ ุจุนุฏูŠู† ุงู„ู€ events ุงู„ู„ูŠ ุจุชุณุจุจ transitionsุŒ ูˆุจุนุฏู‡ุง ุงุฑุณู…. ู…ุชุจุฏุฃุด ุจุงู„ู€ drawing ู…ุจุงุดุฑุฉ โ€” ู…ู…ูƒู† ุชู†ุณู‰ states ุฃูˆ transitions.