Title: UML Example Alarm Clock
1UML ExampleAlarm Clock
2Session Goals
- Demonstrate the documentation of a system
- Includes use of
- Use Cases and Use Case Diagrams
- Class Diagrams
- Sequence Diagrams
3Alarm Clock
- We want the software equivalent of
Set Time
Set Alarm
Alarm On
Alarm Off
Hour
Minute
Snooze
4Use Case Diagram
Alarm Clock
Set Time of Day
Display Hour
ltltincludegtgt
ltltincludegtgt
Set Alarm Time
ltltincludegtgt
ltltincludegtgt
Display Minute
ltltincludegtgt
Disable Alarm
ltltincludegtgt
Enable Alarm
Inform 60 Seconds has elapsed
User
Snooze
Sixty Second Timer
5A Few Elaborations
Use Case Set Alarm Time Main Scenario 1. User
places slider in Set Alarm Position 2. User
determines hour needs to be changed 3. User
presses hour button 4. System increments the
hour of the alarm time (mod 12) 5. Include
Display Hour 6. Repeat steps 3-5 until desired
hour is displayed 7. User determines minute value
needs to change 8. User presses minute
button 9. System increments only the minute of
the alarm time (mod 60) 10. Include Display
Minute 11. Repeat steps 8-10 until desired hour
is displayed Alternate Scenario Hour Doesnt
Need Changing 2. User determines hour value
doesnt need changing 3. Rejoin Main Scenario at
step 6. Alternate Scenario Minute Doesnt Need
Changing 7. User determines minute value doesnt
need changing
6A Few Elaborations
Use Case Display Hour Main Scenario 1. System
determines the new hour is less than 10. 2.
System disables the displays hours tens place
digit. 3. System displays the appropriate digit
of the hours unit place. Alternate Scenario
New hour is equal to 10, 11 or 12 1. System
determines the new hour is equal to 10, 11 or
12. 2. System enables the displays hours tens
place digit (show 1). 3. System set displays
hours unit digit to 0, 1 or 2 appropriately.
Use Case Display Minute Main Scenario 1.
System determines the new minute is less than
10. 2. System displays zero for the minutes tens
place digit. 3. System displays the appropriate
digit of the minutes units place. Alternate
Scenario New minute is greater than 9 1. System
determines the new minute is greater than 9. 2.
System displays the appropriate digit of the
minutes tens place. 3. System displays the
appropriate digit of the minutes units place.
7A Few Elaborations
Use Case Inform 60 Seconds Has Elapsed Main
Scenario 1. Timer informs system that 60 seconds
has elapsed. 2. System increments the current
time by one minute. 3. System displays the new
hour and minute. 4. System determines alarm is
enabled. 5. System determines current time is
equal to alarm time or snooze time. 6. System
sounds alarm. Alternate Scenario Alarm is not
enabled 4. System determines alarm is not
enabled Alternate Scenario Time is not alarm
or snooze time 5. System determines current time
is not alarm time or snooze time.
8Classes
- Clock
- Display
- SixtySecondTimer
- Alarm
- TimeManager
- ButtonManager
- ModeManager
- Time
- Mode (enumeration)
9Classes
- Clock
- This represents the entire clock
- Aggregates all the parts and wires them
together
Clock
- timeMgr TimeManager
- timer SixtySecondTimer
- modeMgr ModeManager
- display Display
- alarm Alarm
- buttonMgr ButtonManager
Clock() start() void
10Classes
- Display
- Represents the interface to the physical display
- Enables the setting of a specific hour and a
specific minute
Display
Display() showHour(newHour int) void
showMinute(newMinute int) void
11Classes
- SixtySecondTimer
- Represents the interface to the physical timer
- Enables us to start the timer and defines what to
do when the timer expires
SixtySecondTimer
- timeMgr TimeManager
- SixtySecondTimer()
- setTimeManager (newTimeMgr TimeManager void
- start() void
- handleTimeout() void
12Class Description
- Alarm
- Represents the interface to the physical alarm
- Provides ability to turn alarm on or off
Alarm
Alarm() on() void off() void
13Class Description
TimeManager
- TimeManager
- Handles the management of various times tracked
by the system - Current time
- Alarm time
- Snooze time
- Provides functionality to increase hour/minute of
each
- currentTime Time
- alarmTime Time
- snoozeTime Time
- display Display
- modeMgr ModeManager
- alarm Alarm
TimeManager() setDisplay(newDisplay
Display) void setModeManager(newModeMgr
ModeManager) void setAlarm(newAlarm Alarm)
void incrementCurrentMinute() void
incrementCurrentHour() void
incrementAlarmHour() void incrementAlarmMinute
() void snooze() void showCurrentTime()
void showAlarmTime() void
14Class Description
- Time
- Represents a specific point in time
- Has resolution of one minute
- Provides for incrementing hour and minute as well
as retrieving hour and minute
Time
- minute int - hour int
Time(initHour int, initMinute int)
addOneMinute() void incrementHour() void
incrementMinute() void getHour() int
getMinute() int equals(time Time) boolean
15Class Description
- ButtonManager
- Provides the handlers for various button events
- Can respond to the press of hour, minute or
snooze button as well as the mode slider - Behaviour depends on current mode
ButtonManager
- modeMgr ModeManager
- timeMgr TimeManager
ButtonManager() doIncrementHour() void
doIncrementMinute() void doSnooze() void
doSetTime() void doSetAlarm() void
doAlarmOn() void doAlarmOff() void
setModeManager(newModeMgr ModeManager) void
setTimeManager(newTimeMgr TimeManager) void
16Class Description
- ModeManager
- Maintains the current mode of the system
- Updating alarm
- Updating time of day
- Showing current time with alarm on
- Showing current time with alarm off
- Enables the getting/setting of the current mode
ModeManager
- currentMode Mode
ModeManager() setMode(newMode Mode)
void getMode() Mode
17Class Description
- Mode
- Enumeration
- Defines literals for each mode the clock may be in
ltltenumerationgtgt Mode
SET_ALARM SET_TIME ALARM_ON ALARM_OFF
18Class Relationships
- Use multiple class diagrams
- Method
- Each diagram typically focuses on one class
- It should the center of the diagram
- It should be fully expanded and complete
- Other class shown should only depict the public
elements used by the focus class
19Clock
TimeManager
SixtySecondTimer
TimeManager() setDisplay(newDisplay
Display) void setModeManager(newModeMgr
ModeManager) void setAlarm(newAlarm Alarm)
void
SixtySecondTimer() setTimeManager (newTimeMgr
TimeManager void start() void
-timer
-timeMgr
Clock
ModeManager
-modeMgr
Display
Clock() start() void
ModeManager()
Display()
-buttonMgr
ButtonManager
Alarm
-alarm
ButtonManager() setModeManager(newModeMgr
ModeManager) void setTimeManager(newTimeMgr
TimeManager) void
Alarm()
20TimeManager
Time
TimeManager
Time(initHour int, initMinute int)
addOneMinute() void incrementHour() void
incrementMinute() void getHour() int
getMinute() int equals(time Time) boolean
TimeManager() setDisplay(newDisplay
Display) void setModeManager(newModeMgr
ModeManager) void setAlarm(newAlarm Alarm)
void incrementCurrentMinute() void
incrementCurrentHour() void
incrementAlarmHour() void incrementAlarmMinute
() void snooze() void showCurrentTime()
void showAlarmTime() void
-modeMgr
ModeManager
getCurrentMode()
Alarm
Display
-display
-alarm
on() off()
showHour(newHour int) void
showMinute(newMinute int) void
21ButtonManager
ButtonManager
TimeManager
incrementCurrentMinute() void
incrementCurrentHour() void
incrementAlarmHour() void incrementAlarmMinute
() void snooze() void showCurrentTime()
void showAlarmTime() void
ButtonManager() doIncrementHour() void
doIncrementMinute() void doSnooze() void
doSetTime() void doSetAlarm() void
doAlarmOn() void doAlarmOff() void
setModeManager(newModeMgr ModeManager) void
setTimeManager(newTimeMgr TimeManager) void
-timeMgr
ltltenumerationgtgt Mode
-modeMgr
ModeManager
SET_ALARM SET_TIME ALARM_ON ALARM_OFF
setMode(newMode Mode) void getMode()
Mode
22SixtySecondTimer
SixtySecondTimer
TimeManager
-timeMgr
- SixtySecondTimer()
- setTimeManager (newTimeMgr TimeManager void
- start() void
- handleTimeout() void
incrementCurrentMinute() void
23ModeManager, Alarm and Display
ltltenumerationgtgt Mode
ModeManager
-currentMode
SET_ALARM SET_TIME ALARM_ON ALARM_OFF
setMode(newMode Mode) void getMode()
Mode
Display
Alarm
Display() showHour(newHour int) void
showMinute(newMinute int) void
Alarm() on() void off() void