0% found this document useful (0 votes)
6 views

C++ 085 DynamicDiagrams

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

C++ 085 DynamicDiagrams

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 33

Advanced Programming Techniques

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

Prof. Dr.-Ing. Peter Fromm Display _A dapter

clear()
Impl_Range

Prof. Dr.-Ing. Michael Lipp


write_str()
<<draft>> w rite_sy mbol()
<<ctor>> init()
D
i
s
Display _Triptime_A larm_A U DI p
Display_Triptime_A larm l
Display_V alue a
O SEK-VGC y
(from SYS) show(v alue : dword) : v oid Display _Mean_C onsumtion_A U DI
Display _Mean_C onsumption S
e
c
t
i
O SEK-win32 Display_C urrent_C onsumption_A U DIo
Display _C urrent_C onsumption
(from SYS) n

Display_Tripdistance Display_Tripdistance_A UDI


console-win32
(from SYS)

"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

 Exploring dynamic diagrams


 Activity Diagram
 Sequence Diagram
 State Diagram

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”

Deployment / Component Diagram


 Perform a high level decomposition
 “How is the system structured”

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?

Three diagrams! Isn’t that enough? Do we


really need some more?

Advanced Programming Techniques Prof. Dr.-Ing. P. Fromm, Prof. Dr.-Ing. M. Lipp 27/11/14 4
What are we missing?

Well, I have to write this very complex


operation. And I really would appreciate to
make a plan of the operation first....

Developer
Advanced Programming Techniques Prof. Dr.-Ing. P. Fromm, Prof. Dr.-Ing. M. Lipp 27/11/14 5
What are we missing?

Hmm, I have this system containing 100


classes and 1000 operations. But I have no
overview of how to use all these
operations. In which order are the
operations called, how do I initialize the
objects,...

Integrator
Advanced Programming Techniques Prof. Dr.-Ing. P. Fromm, Prof. Dr.-Ing. M. Lipp 27/11/14 6
What are we missing?

Great, the software is ready. And I even


have understood all the requirements
thanks to some excellent Use Case
diagrams. But it would be very helpful if I
would know the sequence of operations
and understand the content of the
operations to improve my testcases...

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

Sequence Diagram / Collaboration Diagram


 Used to describe the interactions between objects
 Very useful to describe the call hierarchy e.g. of an API or between
components
 Mainly used on component level close to coding

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

Task: Design the architecture for the control unit of a 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

Code depends on abstraction level.


Example on operation level:

void lecture() {
//Enter room
classroom.enterProf();
classroom.enterStudents();

//Sleep or Listen
if (LectureIsBoring()) {
Student.FallAsleep()
} else {
Student.ListenToProf();
}

//Leave the room


LeaveRoom();
}

Advanced Programming Techniques Prof. Dr.-Ing. P. Fromm, Prof. Dr.-Ing. M. Lipp 27/11/14 13
Activity Diagram
Summary

 Used to show the flow of activities and decisions


 Can be used on high (requirements) and low (code) level

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

Basic Elements Together supports generation of


 Objects Sequence Diagrams out of code
 Messages

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

Inherited operations are treated like “normal” operations.

Advanced Programming Techniques Prof. Dr.-Ing. P. Fromm, Prof. Dr.-Ing. M. Lipp 27/11/14 16
Sequence Diagram

Aggregated operations are not visible, they must be drawn explicitly to


the object providing them.

Advanced Programming Techniques Prof. Dr.-Ing. P. Fromm, Prof. Dr.-Ing. M. Lipp 27/11/14 17
Sequence Diagram

The same content as collaboration 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

 Used to show the communication flow (e.g. call of operations)


between a set of objects
 Sequence diagrams and collaboration diagrams are different
representations of the same content
 Sequence diagram: focus on timeline
 Collaboration Diagram: focus on object structure

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

 Rounded rectangle, denoting a state. Top of the rectangle contains a


name of the state. Can contain a horizontal line in the middle, below
which the activities that are done in that state are indicated
 Arrow, denoting transition. The name of the event (if any) causing this
transition labels the arrow body. A guard expression may be added
before a "/" and enclosed in square-brackets ( eventName
[guardExpression] ), denoting that this expression must be true for
the transition to take place. If an action is performed during this
transition, it is added to the label following a "/" ( eventName
[guardExpression]/action ).

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

 Used to describe reactive systems (e.g. systems reacting on a user


input)
 Can be used on conceptual and implementation level

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

Activity Diagram State Diagram


 Focus on the activities  Focus on the program logic
 Describe sequential activities  Describes the reaction of the
software on events
 Activity: Operation
 State: Attribute
 Transition: Change state, trigger
action
 Event, IRQ, Signal, Logical
Decision: Trigger Transition

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

System Architecture ready


Use Case
Activity
Component Class
Coding starts
State

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

 Generate Model Structure (folders)


 System Level (Architecture)
 Generate Use Case Diagrams
 Generate Component / Deployment Diagrams
 Generate State Diagram(s)
 Component Level
 Generate Use Case and Activity Diagrams
 Generate Class Diagrams and Code Framework
 Generate Sequence Diagrams
 Generate State Diagrams (optional)

Advanced Programming Techniques Prof. Dr.-Ing. P. Fromm, Prof. Dr.-Ing. M. Lipp 27/11/14 32
Wrap-Up

We now have a complete overview of the UML 1.4 standard!

Advanced Programming Techniques Prof. Dr.-Ing. P. Fromm, Prof. Dr.-Ing. M. Lipp 27/11/14 33

You might also like