lecture 10 state machines overview
play

Lecture 10: State Machines Overview 2015-12-03 Prof. Dr. Andreas - PowerPoint PPT Presentation

Software Design, Modelling and Analysis in UML Lecture 10: State Machines Overview 2015-12-03 Prof. Dr. Andreas Podelski, Dr. Bernd Westphal 10 2015-12-03 main Albert-Ludwigs-Universit at Freiburg, Germany Contents &


  1. Software Design, Modelling and Analysis in UML Lecture 10: State Machines Overview 2015-12-03 Prof. Dr. Andreas Podelski, Dr. Bernd Westphal – 10 – 2015-12-03 – main – Albert-Ludwigs-Universit¨ at Freiburg, Germany

  2. Contents & Goals Last Lecture: • (Mostly) completed discussion of modelling structure . This Lecture: • Educational Objectives: Capabilities for following tasks/questions. • What’s the purpose of a behavioural model? • What does this State Machine mean? What happens if I inject this event? • Can you please model the following behaviour. • Content: • For completeness: Modelling Guidelines for Class Diagrams • Purposes of Behavioural Models – 10 – 2015-12-03 – Sprelim – • UML Core State Machines 2 /33

  3. Design Guidelines for (Class) Diagram (partly following Ambler (2005)) – 10 – 2015-12-03 – main – 3 /33

  4. General Diagramming Guidelines Ambler (2005) (Note: “Exceptions prove the rule.”) • 2.1 Readability • 1.–3. Support Readability of Lines • 4. Apply Consistently Sized Symbols • 9. Minimize the Number of Bubbles • 10. Include White-Space in Diagrams • 13. Provide a Notational Legend – 10 – 2015-12-03 – Selements – 4 /33

  5. General Diagramming Guidelines Ambler (2005) • 2.2 Simplicity • 14. Show Only What You Have to Show • 15. Prefer Well-Known Notation over Exotic Notation • 16. Large vs. Small Diagrams • 18. Content First, Appearance Second – 10 – 2015-12-03 – Selements – 5 /33

  6. General Diagramming Guidelines Ambler (2005) • 2.2 Simplicity • 14. Show Only What You Have to Show • 15. Prefer Well-Known Notation over Exotic Notation • 16. Large vs. Small Diagrams • 18. Content First, Appearance Second • 2.3 Naming • 20. Set and (23. Consistently) Follow Effective Naming Conventions – 10 – 2015-12-03 – Selements – • 2.4 General • 24. Indicate Unknowns with Question-Marks • 25. Consider Applying Color to Your Diagram • 26. Apply Color Sparingly 5 /33

  7. Class Diagram Guidelines Ambler (2005) • 5.1 General Guidelines • 88. Indicate Visibility Only on Design Models (in contrast to analysis models) • 5.2 Class Style Guidelines • 96. Prefer Complete Singular Nouns for Class Names • 97. Name Operations with Strong Verbs • 99. Do Not Model Scaffolding Code [Except for Exceptions] – 10 – 2015-12-03 – Selements – 6 /33

  8. Class Diagram Guidelines Ambler (2005) • 5.2 Class Style Guidelines • 103. Never Show Classes with Just Two Compartments • 104. Label Uncommon Class Compartments • 105. Include an Ellipsis (...) at the End of an Incomplete List • 107. List Operations/Attributes in Order of Decreasing Visibility – 10 – 2015-12-03 – Selements – 7 /33

  9. Class Diagram Guidelines Ambler (2005) • 5.3 Relationships • 112. Model Relationships Horizontally • 115. Model a Dependency When the Relationship is Transitory • 117. Always Indicate the Multiplicity • 118. Avoid Multiplicity “ ∗ ” • 119. Replace Relationship Lines with Attribute Types – 10 – 2015-12-03 – Selements – 8 /33

  10. Class Diagram Guidelines Ambler (2005) • 5.4 Associations • 127. Indicate Role Names When Multiple Associations Between Two Classes Exist • 129. Make Associations Bidirectional Only When Collaboration Occurs in Both Directions • 131. Avoid Indicating Non-Navigability • 133. Question Multiplicities Involving Minimums and Maximums • 5.6 Aggregation and Composition – 10 – 2015-12-03 – Selements – • → exercises 9 /33

  11. Example: Modelling Games – 10 – 2015-12-03 – main – 10 /33

  12. Task: Game Development Task : develop a video game . Genre : Racing . Rest : open , i.e. Degrees of freedom: Exemplary choice: 2D-Tron • simulation vs. arcade arcade • platform (SDK or not, open open or proprietary, hardware capabilities...) • graphics (3D, 2D, ...) 2D • number of players, AI min. 2, AI open • controller open (later determined by platform) • game experience minimal: main menu and game – 10 – 2015-12-03 – Stron – 11 /33

  13. Modelling Structure: 2D-Tron 2D-Tron • arcade • platform open • 2D • In many domains, there are canonical • min. 2, AI open architectures – and adept readers try • controller open to see/find/match this! • only game, no menues • For games: Main Game Logic External Output ? • player scores inputs • Graphics (from • interface inputs/engine ASCII to bitmap; • Keyboard ? native or via API) – 10 – 2015-12-03 – Stron – update notify • Joystick • Sound • . . . (Physics) Engine • . . . • physical objects • collision notification 12 /33

  14. Modelling Structure: 2D-Tron Main ? Game Logic External Output ? inputs update notify (Physics) Engine Tron Player Joystick? OpenGL? 1 .. ∗ colour 1 .. ∗ score . . . . . . Control Gameplay Render direction speed Keyboard? aalib? update notify head – 10 – 2015-12-03 – Stron – Segment Engine Conventions: x0, y0 areawidth x1, y1 AI? • default µ is 1 areaheight colour 0 .. ∗ world • default ξ is + 13 /33

  15. Modelling Behaviour – 10 – 2015-12-03 – main – 14 /33

  16. Stocktaking... Have: Means to model the structure of the system. • Class diagrams graphically, concisely describe sets of system states. • OCL expressions logically state constraints/invariants on system states. Want: Means to model behaviour of the system. • Means to describe how system states evolve over time , that is, to describe sets of sequences σ 0 , σ 1 , · · · ∈ Σ ω of system states . – 10 – 2015-12-03 – Sbehav – 15 /33

  17. What Can Be Purposes of Behavioural Models? 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: • Require Behaviour. “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.) • Allow Behaviour. “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.) • Forbid Behaviour. “System never does this” – 10 – 2015-12-03 – Sbehav – “This sequence of getting both, a water and all money back, must not be possible.” (Otherwise the software is broken.) Note : the latter two are trivially satisfied by doing nothing... 16 /33

  18. Constructive Behaviour in UML UML provides two visual formalisms for constructive description of behaviours: • Activity Diagrams • State-Machine Diagrams We (exemplary) focus on State-Machines because • somehow “practice proven” (in different flavours), • prevalent in embedded systems community, • indicated useful by Dobing and Parsons (2006) survey, and • Activity Diagram’s intuition changed (between UML 1.x and 2.x) from transition-system-like to petri-net-like... • Example state machines: – 10 – 2015-12-03 – Sbehav – • E [ n � = ∅ ] /x := x + 1; n ! F s 1 s 2 • F/ s 1 s 2 /n := ∅ F/x := 0 /p ! F s 3 17 /33

  19. Course Map N UML W E CD , SM ϕ ∈ OCL CD , SD S ! ✔ ✔ Model S = ( T , C , V, atr ) , SM S , SD expr ! ✔ ✔ M = (Σ D S , A S , → SM ) B = ( Q SD , q 0 , A S , → SD , F SD ) ✔ ! ( cons 0 , Snd 0 ) π = ( σ 0 , ε 0 ) − − − − − − − − → ( σ 1 , ε 1 ) · · · w π = (( σ i , cons i , Snd i )) i ∈ N Instances u 0 ✔ Mathematics G = ( N, E, f ) – 10 – 2015-12-03 – Sbehav – ✔ OD UML 18 /33

  20. UML State Machines: Overview – 10 – 2015-12-03 – main – 19 /33

  21. UML State Machines • E [ n � = ∅ ] /x := x + 1; n ! F s 1 s 2 /n := ∅ F/x := 0 s 3 Brief History : • Rooted in Moore/Mealy machines , Transition Systems, etc. • Harel (1987): Statecharts as a concise notation, introduces in particular hierarchical states. • Manifest in tool Statemate Harel et al. (1990) (simulation, code-generation); nowadays also in Matlab/Simulink , etc. • From UML 1.x on: State Machines – 10 – 2015-12-03 – Sstmover – (not the official name, but understood: UML-Statecharts ) • Late 1990’s: tool Rhapsody with code-generation for state machines. Note : there is a common core, but each dialect interprets some constructs subtly different Crane and Dingel (2007). (Would be too easy otherwise. . . ) 20 /33

  22. Roadmap: Chronologically Syntax : (i) UML State Machine Diagrams. (ii) Def.: Signature with signals . N UML (iii) Def.: Core state machine . W E (iv) Map UML State Machine Diagrams CD , SM ϕ ∈ OCL CD , SD S ! ✔ to core state machines. ✔ Model S = ( T , C , V, atr ) , SM S , SD expr ! ✔ Semantics : ✔ M = (Σ D S , A S , → SM ) B = ( Q SD , q 0 , A S , → SD , F SD ) The Basic Causality Model ✔ (v) Def.: Ether (aka. event pool) ! ( cons 0 , Snd 0 ) π = ( σ 0 , ε 0 ) − − − − − − − − → ( σ 1 , ε 1 ) · · · w π = (( σ i , cons i , Snd i )) i ∈ N (vi) Def.: System configuration . Instances u 0 ✔ (vii) Def.: Event . Mathematics G = ( N, E, f ) (viii) Def.: Transformer . ✔ OD UML (ix) Def.: Transition system , computation. – 10 – 2015-12-03 – Sstmover – (x) Transition relation induced by core state machine. (xi) Def.: step , run-to-completion step . (xii) Later: Hierarchical state machines. 21 /33

  23. UML State Machines: Syntax – 10 – 2015-12-03 – main – 22 /33

Recommend


More recommend