Software Design, Modelling and Analysis in UML
Lecture 10: Constructive Behaviour, State Machines Overview
2013-12-02
- Prof. Dr. Andreas Podelski, Dr. Bernd Westphal
Albert-Ludwigs-Universit¨ at Freiburg, Germany
– 10 – 2013-12-02 – main –
Software Design, Modelling and Analysis in UML Lecture 10: - - PowerPoint PPT Presentation
Software Design, Modelling and Analysis in UML Lecture 10: Constructive Behaviour, State Machines Overview 2013-12-02 10 2013-12-02 main Prof. Dr. Andreas Podelski, Dr. Bernd Westphal Albert-Ludwigs-Universit at Freiburg,
2013-12-02
Albert-Ludwigs-Universit¨ at Freiburg, Germany
– 10 – 2013-12-02 – main –
Last Lecture:
This Lecture:
behaviour?
– 10 – 2013-12-02 – Sprelim –
2/96
– 10 – 2013-12-02 – main –
3/96
C
v : τ {v > 3}
If
C D consists of only CD with the single class C, then– 10 – 2013-12-02 – Socldia –
4/96
Find the 10 differences: C
x : Int {x = 3 ∨ x > 17}
C
x : T
D(T) = {3}∪{n ∈ N | n > 17}
a system state satisfying x = 4 violates the constraints of the diagram.
there cannot be a system state with σ(u)(x) = 4 because σ(u)(x) is supposed to be in
D(T) (by definition of system state).Rule-of-thumb:
correspondence in the application domain), then make it a type.
then make it a constraint.
– 10 – 2013-12-02 – Socldia –
5/96
Definition.
Let
C D be a set of class diagrams.We say, the semantics of
C D is the signature it induces and the set ofOCL constraints occurring in
C D, denoted JC D K := S (C D), Inv(C D).Given a structure
D of S (and thus of C D), the class diagrams describethe system states Σ
D S . Of those, some satisfy Inv(C D) and some don’t.We call a system state σ ∈ Σ
D S consistent if and only if σ |= Inv(C
D).In pictures:
C D = {CD1, . . . , CDn}signature
S (C D)invariants Inv(C
D)basic (classes and attributes) extended (visibility) (σ ∈) Σ
D S J · Kdistinguish induce
– 10 – 2013-12-02 – Socldia –
6/96
Recall: a UML model is an image or pre-image of a software system. A set of class diagrams
C D with invariants Inv(C D) describes the structureTogether with the invariants it can be used to state:
uses only system states that satisfy Inv(C
D).states which satisfy Inv(C
D) are used.(The exact meaning of “use” will become clear when we study behaviour — intuitively: the system states that are reachable from the initial system state(s) by calling methods or firing transitions in state-machines.)
Example: highly abstract model of traffic lights controller.
TLCtrl
red : Bool green : Bool
not(red and green)
– 10 – 2013-12-02 – Socldia –
7/96
– 10 – 2013-12-02 – main –
8/96
– 10 – 2013-12-02 – Sblank –
9/96
188 Object Constraint Language, v2.0
Table A.2 - Semantics of boolean operations
b1 b2 b1 and b2 b1 or b2 b1 xor b2 b1 implies b2 not b1 false false false false false true true false true false true true true true true false false true true false false true true true true false true false false A false A A true true true A A true A A false
A.2.2 Common Operations On All Types
A false false A A A A A true A true A true A A A A A A A A
Table A.2 - Semantics of boolean operations
– 10 – 2013-12-02 – main –
10/96
Be careful whose advice you buy, but, be patient with those who supply it.
Baz Luhrmann/Mary Schmich
(partly following [Ambler, 2005])
– 10 – 2013-12-02 – main –
11/96
“Imagine you’re given your diagram D and asked to conduct task T .
(semantics sufficiently clear? all necessary information available? ...)
(syntactical well-formedness? readability? intention of deviations from standard syntax clear? reasonable selection of information? layout? ...)
In other words:
– 10 – 2013-12-02 – Selements –
12/96
Examples for purposes and points and rules-of-thumb:
(C0,1 is easy for Java, C∗ comes at a cost — other way round for RDB)
concepts, the architecture, the difficult part”
“outdated/wrong documentation is worse than none”
– 10 – 2013-12-02 – Selements –
13/96
(Note: “Exceptions prove the rule.”)
– 10 – 2013-12-02 – Selements –
14/96
(Note: “Exceptions prove the rule.”)
– 10 – 2013-12-02 – Selements –
14/96
– 10 – 2013-12-02 – Selements –
15/96
– 10 – 2013-12-02 – Selements –
15/96
– 10 – 2013-12-02 – Selements –
16/96
– 10 – 2013-12-02 – Selements –
17/96
– 10 – 2013-12-02 – Selements –
18/96
Exist
Both Directions
– 10 – 2013-12-02 – Selements –
19/96
[...] But trust me on the sunscreen.
Baz Luhrmann/Mary Schmich
– 10 – 2013-12-02 – main –
20/96
– 10 – 2013-12-02 – main –
21/96
Task: develop a video game. Genre: Racing. Rest: open, i.e. Degrees of freedom: Exemplary choice: 2D-Tron
arcade
hardware capabilities...)
2D
minimal: main menu and game
– 10 – 2013-12-02 – Stron –
22/96
2D-Tron
architectures – and adept readers try to see/find/match this!
Main External inputs
Game Logic
(Physics) Engine
Output
ASCII to bitmap; native or via API)
notify update ? ?
– 10 – 2013-12-02 – Stron –
23/96
Main External inputs Game Logic (Physics) Engine Output notify update ? ?
Tron Joystick? . . . Keyboard? Control Player
colour score direction speed
Gameplay Render OpenGL? . . . aalib? AI? Segment
x0, y0 x1, y1 colour
Engine
areawidth areaheight
1..∗ notify update 0..∗ head world 1..∗ Conventions:
– 10 – 2013-12-02 – Stron –
24/96
– 10 – 2013-12-02 – main –
25/96
Have: Means to model the structure of the system.
Want: Means to model behaviour of the system.
that is, to describe sets of sequences σ0, σ1, · · · ∈ Σω
– 10 – 2013-12-02 – Sbehav –
26/96
(We will discuss this in more detail in Lecture 22.) Example: Pre-Image Image
(the UML model is supposed to be the blue-print for a software system).
A description of behaviour could serve the following purposes:
“System definitely does this”
“This sequence of inserting money and requesting and getting water must be possible.” (Otherwise the software for the vending machine is completely broken.)
“System does subset of this”
“After inserting money and choosing a drink, the drink is dispensed (if in stock).” (If the implementation insists on taking the money first, that’s a fair choice.)
“System never does this”
“This sequence of getting both, a water and all money back, must not be pos- sible.” (Otherwise the software is broken.)
Note: the latter two are trivially satisfied by doing nothing...
– 10 – 2013-12-02 – Sbehav –
28/96
[Harel, 1997] proposes to distinguish constructive and reflective descriptions:
executing the model or in translating it into executable code.” A constructive description tells how things are computed (which can then be desired or undesired).
system modeler to capture parts of the thinking that go into building the model – behavior included –, to derive and present views of the model, statically or during execution, or to set constraints on behavior in preparation for verification.” A reflective description tells what shall or shall not be computed. Note: No sharp boundaries!
– 10 – 2013-12-02 – Sbehav –
29/96
UML provides two visual formalisms for constructive description of behaviours:
We (exemplary) focus on State-Machines because
transition-system-like to petri-net-like...
s1 s2 s3
E[n = ∅]/x := x + 1; n ! F /n := ∅ F/x := 0
– 10 – 2013-12-02 – Sbehav –
30/96
N S W E
CD, SM
S = (T, C, V, atr), SMM = (Σ
D S , A S , →SM )ϕ ∈ OCL expr CD, SD
S , SDB = (QSD, q0, A
S , →SD, FSD)π = (σ0, ε0)
(cons0,Snd0)
− − − − − − − − →
u0
(σ1, ε1)· · · wπ = ((σi, consi, Sndi))i∈N G = (N, E, f)
OD
– 10 – 2013-12-02 – Sbehav –
31/96
– 10 – 2013-12-02 – main –
95/96
[Ambler, 2005] Ambler, S. W. (2005). The Elements of UML 2.0 Style. Cambridge University Press. [Crane and Dingel, 2007] Crane, M. L. and Dingel, J. (2007). UML vs. classical vs. rhapsody statecharts: not all models are created equal. Software and Systems Modeling, 6(4):415–435. [Dobing and Parsons, 2006] Dobing, B. and Parsons, J. (2006). How UML is used. Communications of the ACM, 49(5):109–114. [Harel, 1987] Harel, D. (1987). Statecharts: A visual formalism for complex systems. Science of Computer Programming, 8(3):231–274. [Harel, 1997] Harel, D. (1997). Some thoughts on statecharts, 13 years later. In Grumberg, O., editor, CAV, volume 1254 of LNCS, pages 226–231. Springer-Verlag. [Harel and Gery, 1997] Harel, D. and Gery, E. (1997). Executable object modeling with statecharts. IEEE Computer, 30(7):31–42. [Harel et al., 1990] Harel, D., Lachover, H., et al. (1990). Statemate: A working environment for the development of complex reactive systems. IEEE Transactions
[OMG, 2007a] OMG (2007a). Unified modeling language: Infrastructure, version 2.1.2. Technical Report formal/07-11-04.
– 10 – 2013-12-02 – main –
96/96