C++ 085 DynamicDiagrams
C++ 085 DynamicDiagrams
Dynamic Diagrams
State_C ontrol
Signal_A dapter C
State_C ontrol_A UDI o
on_ select_prev () n
init() on_select_next() t
raise_tick() on_tick() on_select_next() r
raise_select_prev () on_triptime_alarm() on_tick() o
raise_select_next() 1 on_mem_lev el_dow n() on_triptime_alarm() l
raise_triptime_alarm() on_mem_lev el_up() on_ select_prev ()
raise_ignition_on() on_mem_lev el_dow n() S
on_ignition_on() e
raise_ignition_off() on_ignition_off() on_mem_lev el_up() c
raise_reset_program() on_reset_program() on_ignition_off() t
raise_reset_all_programs() on_reset_all_programs() on_ignition_on() i
raise_eeprom_changed() on_eeprom_changed() reset_program() o
raise_memlev el_down() reset_all_programs() n
<<ctor>> init()
raise_memlev el_up() Create()
Impl_Tripdistance_A UDI C
Impl_Tripdistance
Program a
Data_Adapter l
c
calc_v alue() : v oid u
display () : v oid Imp_Triptime_Alarm l
ignition_on() : v oid Impl_Triptime_A larm_A UDI a
ignition_off() : void t
i
reset() : v oid Impl_Triptime o
<<?>> eeprom_changed() : ... n
need_recalc() : bool
Impl_Mean_C onsumption_A U DI S
Impl_Mean_C onsumption e
c
t
i
Impl_C urrent_C onsumption Impl_C urrent_C onsumption_AUDIo
n
Impl_Average_Speed
clear()
Impl_Range
"classes " of lefthand coloumns in the middel build up the trip computer core. The classes on the right side all
coloumn act as inerface to A ll code has to be independent of manufacturer. belong to the A UDI package
hareware and O S. They and are not part of the main class
are declared abstract in the The Impl_XXX and Display_XXX classes describe what flav ours of program hierarchy.
main class hierarchy and functionality are expected
implemented in several They are included to show where
SYS packages. the main class hierarchy has to be
expanded for manufactorer's
requirements
Content
Advanced Programming Techniques Prof. Dr.-Ing. P. Fromm, Prof. Dr.-Ing. M. Lipp 27/11/14 2
Wrap-Up
User / Functional
Use Case Diagram
Perspective
Describe functional requirements
“What are we going to do with the system”
Class Diagram
Perspective
Technical /
Developer
Perform a low level decomposition
“How will the system be implemented”
Advanced Programming Techniques Prof. Dr.-Ing. P. Fromm, Prof. Dr.-Ing. M. Lipp 27/11/14 3
What are we missing?
Advanced Programming Techniques Prof. Dr.-Ing. P. Fromm, Prof. Dr.-Ing. M. Lipp 27/11/14 4
What are we missing?
Developer
Advanced Programming Techniques Prof. Dr.-Ing. P. Fromm, Prof. Dr.-Ing. M. Lipp 27/11/14 5
What are we missing?
Integrator
Advanced Programming Techniques Prof. Dr.-Ing. P. Fromm, Prof. Dr.-Ing. M. Lipp 27/11/14 6
What are we missing?
Tester
Advanced Programming Techniques Prof. Dr.-Ing. P. Fromm, Prof. Dr.-Ing. M. Lipp 27/11/14 7
What are we missing?
Advanced Programming Techniques Prof. Dr.-Ing. P. Fromm, Prof. Dr.-Ing. M. Lipp 27/11/14 8
Behavior Diagram Overview
Activity Diagram
Flow Chart describing the “steps” of an functionality / operation
Very useful for sequential systems or operations
Can be used for requirements analysis down to the code
State Diagram
Used to describe the state a software is in
Very useful to describe reactive (events) systems or operations
Can be used for architecture description down to the code
Advanced Programming Techniques Prof. Dr.-Ing. P. Fromm, Prof. Dr.-Ing. M. Lipp 27/11/14 9
System Design: Snackmachine
First step
Describe the user interactions (requirements)
Create a static design (structuring)
Second step
Validate the design
Develop an implementation strategy
Advanced Programming Techniques Prof. Dr.-Ing. P. Fromm, Prof. Dr.-Ing. M. Lipp 27/11/14 10
Activity Diagram
Basic Elements
Start, End
Activities
Transitions
Decision
Activity
Program sequence
Advanced Programming Techniques Prof. Dr.-Ing. P. Fromm, Prof. Dr.-Ing. M. Lipp 27/11/14 11
Activity Diagram
Extended Elements
Notes
Messages
Swimlanes
Synchronization
bars (Fork/Join)
Advanced Programming Techniques Prof. Dr.-Ing. P. Fromm, Prof. Dr.-Ing. M. Lipp 27/11/14 12
Activity Diagram and Code
void lecture() {
//Enter room
classroom.enterProf();
classroom.enterStudents();
//Sleep or Listen
if (LectureIsBoring()) {
Student.FallAsleep()
} else {
Student.ListenToProf();
}
Advanced Programming Techniques Prof. Dr.-Ing. P. Fromm, Prof. Dr.-Ing. M. Lipp 27/11/14 13
Activity Diagram
Summary
Good practice:
When used on code level for describing an operation: Copy the
activity descriptions as comment into the code before coding
Advanced Programming Techniques Prof. Dr.-Ing. P. Fromm, Prof. Dr.-Ing. M. Lipp 27/11/14 14
Sequence Diagram
Messages:
Operations
OS-Messages
Note:
Relevant
Operations only!
Time
Advanced Programming Techniques Prof. Dr.-Ing. P. Fromm, Prof. Dr.-Ing. M. Lipp 27/11/14 15
Sequence Diagram
Advanced Programming Techniques Prof. Dr.-Ing. P. Fromm, Prof. Dr.-Ing. M. Lipp 27/11/14 16
Sequence Diagram
Advanced Programming Techniques Prof. Dr.-Ing. P. Fromm, Prof. Dr.-Ing. M. Lipp 27/11/14 17
Sequence Diagram
Advanced Programming Techniques Prof. Dr.-Ing. P. Fromm, Prof. Dr.-Ing. M. Lipp 27/11/14 18
Sequence Diagram and Code
In triangle.cpp
this->setPosition;
oCorner[0].set();
oCorner[1].set();
Advanced Programming Techniques Prof. Dr.-Ing. P. Fromm, Prof. Dr.-Ing. M. Lipp 27/11/14 19
Sequence Diagram
Summary
Good practice
The sequence diagram should provide an overview. Details like loops
or if-statements should be avaoided
Advanced Programming Techniques Prof. Dr.-Ing. P. Fromm, Prof. Dr.-Ing. M. Lipp 27/11/14 20
State Diagram
Basic Elements
State
Transition
Event
Action
Guard
Transition:
event[Guard]/Action
Advanced Programming Techniques Prof. Dr.-Ing. P. Fromm, Prof. Dr.-Ing. M. Lipp 27/11/14 21
State Diagram
Extended Elements
State Hierarchy
History State
Advanced Programming Techniques Prof. Dr.-Ing. P. Fromm, Prof. Dr.-Ing. M. Lipp 27/11/14 22
State Diagram
Extended description
eventName [guardExpression]/action
Advanced Programming Techniques Prof. Dr.-Ing. P. Fromm, Prof. Dr.-Ing. M. Lipp 27/11/14 23
State Diagram and Code
ev = getEvent();
switch (state) {
case Idle:
if ((ev==ButtonPressed()) && (HoldNotActive)) {
state = PlaySong;
}
break;
case PlaySong:
if ((ev==ButtonPressed(MENU)) && (HoldNotActive)) {
state=SelectSong;
OpenSelectMenu();
}
if ((ev==ButtonPressed(STOP)) && (HoldNotActive)) {
state=Idle;
}
...
Advanced Programming Techniques Prof. Dr.-Ing. P. Fromm, Prof. Dr.-Ing. M. Lipp 27/11/14 24
State Diagram and Code
Alternative switch structure
ev = getEvent();
switch (ev) {
case ButtonPressed_STOP:
switch (state):
case idle:
....
break;
case PlaySong:
...
break;
case ButtonPressed_PLAY:
switch (state):
case idle:
....
break;
case PlaySong:
...
break;
...
Advanced Programming Techniques Prof. Dr.-Ing. P. Fromm, Prof. Dr.-Ing. M. Lipp 27/11/14 25
State Diagram
Good practice:
Danger: Logic described in diagram is “lost in code”
State Diagrams therefore should be mapped to code using pattern
like switch-case or mapping-table, improving maintainability.
Advanced Programming Techniques Prof. Dr.-Ing. P. Fromm, Prof. Dr.-Ing. M. Lipp 27/11/14 26
Differences between state and activity
diagram
Advanced Programming Techniques Prof. Dr.-Ing. P. Fromm, Prof. Dr.-Ing. M. Lipp 27/11/14 27
Example: MP3 Player
List all
Events
Actions
States
Advanced Programming Techniques Prof. Dr.-Ing. P. Fromm, Prof. Dr.-Ing. M. Lipp 27/11/14 28
Example: MP3 Player
Advanced Programming Techniques Prof. Dr.-Ing. P. Fromm, Prof. Dr.-Ing. M. Lipp 27/11/14 29
Diagrams and Abstraction Level
User
Case
Use
Component
System
Activity
Sequence
Component
Case
State
Class
Use
Operation
Advanced Programming Techniques Prof. Dr.-Ing. P. Fromm, Prof. Dr.-Ing. M. Lipp 27/11/14 30
Diagrams and Project Timeline
Component Class
Use Case Sequence
Activity
State
Prepare Produce t
Advanced Programming Techniques Prof. Dr.-Ing. P. Fromm, Prof. Dr.-Ing. M. Lipp 27/11/14 31
Together Recipe
Advanced Programming Techniques Prof. Dr.-Ing. P. Fromm, Prof. Dr.-Ing. M. Lipp 27/11/14 32
Wrap-Up
Advanced Programming Techniques Prof. Dr.-Ing. P. Fromm, Prof. Dr.-Ing. M. Lipp 27/11/14 33