Modeling Dynamic Behavior: State and Activity Diagrams.

Slides:



Advertisements
Similar presentations
© 2005 by Prentice Hall Appendix 3 Object-Oriented Analysis and Design Modern Systems Analysis and Design Fourth Edition Jeffrey A. Hoffer Joey F. George.
Advertisements

State Charts Mehran Najafi. Reactive Systems A reactive, event-driven, object is one whose behavior is best characterized by its response to events dispatched.
UML State chart/machine diagram State machine diagram is a behavior diagram which shows discrete behavior of a part of designed system through finite state.
Activity Diagrams in UML. Definition Activity diagrams represent the dynamics of the system. They are flow charts that are used to show the workflow of.
ESE Einführung in Software Engineering 7. Modeling Behaviour Prof. O. Nierstrasz.
Introduction to Software Engineering 7. Modeling Behaviour.
© 2006 ITT Educational Services Inc. SE350 System Analysis for Software Engineers: Unit 9 Slide 1 Appendix 3 Object-Oriented Analysis and Design.
Chapter 8: Modelling Interactions and Behaviour
State Change Modelling. Aim: To introduce the concept and techniques for describing the changes in state that may occur to an object in its lifetime.
Chapter 8: Modelling Interactions and Behaviour
Modern Systems Analysis and Design Fifth Edition Jeffrey A
Advanced Behavioral Modeling
Modeling Dynamic Behavior: Sequence and Collaboration Diagrams.
Practical Object-Oriented Design with UML 2e Slide 1/1 ©The McGraw-Hill Companies, 2004 PRACTICAL OBJECT-ORIENTED DESIGN WITH UML 2e Chapter 10: Statecharts.
SE-565 Software System Requirements More UML Diagrams.
Object-Oriented Software Engineering Practical Software Development using UML and Java Chapter 8: Modelling Interactions and Behaviour.
Software Engineering EKT 420. What is Activity Diagram Activity diagrams are graphical representations of workflows of stepwise activities and actions.
State and Sequence Diagrams Modelling dynamic information So far we have seen: Use Case Diagrams – requirements capture, interface.
State Machines State diagrams SE-2030 Dr. Rob Hasker 1 Based on slides written by Dr. Mark L. Hornick Used with permission.
Chapter 10 State Machine Diagrams
Object-Oriented Software Engineering Practical Software Development using UML and Java Chapter 8: Modelling Interactions and Behaviour.
Object-Oriented Software Engineering Practical Software Development using UML and Java Chapter 8: Modelling Interactions and Behaviour.
Modelling Interactions and Behaviour. © Lethbridge/Laganière 2005 Chapter 8: Modelling Interactions and Behaviour2 Interaction Diagrams Interaction diagrams.
Chapter 8: Modelling Interactions and Behaviour UML Activity Diagram
Slide 16B.51 © The McGraw-Hill Companies, 2005 Object-Oriented and Classical Software Engineering.
Object-Oriented Software Engineering Practical Software Development using UML and Java Chapter 8: Modelling Interactions and Behaviour.
 2000 Deitel & Associates, Inc. All rights reserved. Optional Case Study - Chapter 3 Outline 3.1 Introduction 3.2 Class Attributes 3.3 Statechart Diagrams.
1 Modeling interactions and behavior Lecturer Dr. Mai Fadel.
Modelling interactions and behaviour Adapted after : Timothy Lethbridge and Robert Laganiere, Object-Oriented Software Engineering – Practical Software.
UML -Part 3. Dynamic Diagram Types Interaction Diagrams - Set of objects or roles and the messages that can be passed among them. – Sequence Diagrams.
Activity diagrams. Introduction ● Activity diagrams are a behavioural model that represent the dynamics of the system. ● An activity diagram is essentially.
University of Toronto at Scarborough © Kersti Wain-Bantin CSCC40 state charts 1 object states an object state is a condition or situation during the life.
Discovering object interaction. Use case realisation The USE CASE diagram presents an outside view of the system. The functionality of the use case is.
Course Instructor: Kashif Ihsan 1. Chapter # 3 2.
Modeling with UML The Unified Modeling Language (UML) is a standard graphical language for modeling an object-oriented software by providing a standard.
Information System Design IT60105
1 Kyung Hee University Statecharts Spring Kyung Hee University Specifying Objects’ Behaviour  Interaction diagrams show message-passing behaviour.
CSE 240 Lecture 11. Quote of the day "The ideal engineer is a composite... He is not a scientist, he is not a mathematician, he is not a sociologist or.
CSCI-383 Object-Oriented Programming & Design Lecture 12.
Chapter 11 Activity Diagrams. 2 “Activity diagrams are a technique to describe procedural logic, business processes, and work flows” - M. Fowler An activity.
State Modeling. Introduction A state model describes the sequences of operations that occur in response to external stimuli. As opposed to what the operations.
CS212: Object Oriented Analysis and Design Lecture 34: UML Activity and Collaboration diagram.
States.
CS3773 Software Engineering Lecture 06 UML State Machines.
Interaction Diagram An interaction diagram is a graphical representation of interactions between objects. Sequence diagram: shows the sequence in which.
SOFTWARE DESIGN AND ARCHITECTURE LECTURE 26. Review UML behavioral Diagrams – Sequence diagram.
Essentials of Visual Modeling w/ UML Instructor Notes
Object-Oriented Software Engineering Practical Software Development using UML and Java Chapter 8: Modelling Interactions and Behaviour Based on Presentations.
Practical Object-Oriented Design with UML 2e Slide 1/1 ©The McGraw-Hill Companies, 2004 PRACTICAL OBJECT-ORIENTED DESIGN WITH UML 2e Chapter 10: Statecharts.
UML Activity Diagrams.
Chapter 3: Introducing the UML
Modeling Object Lifecycles and State-Dependent Behavior ©SoftMoore ConsultingSlide 1.
 Activity diagram is basically a flow chart to represent the flow from one activity to another activity.
Object-Oriented Software Engineering Practical Software Development using UML and Java Chapter 8: Modelling Interactions and Behaviour.
State Machine Model.
State Machine Diagram.
State Machine Diagrams
Activity Diagram.
Activity and State Transition Diagram
State Machine Diagrams
Chapter 8: Modelling Interactions and Behaviour UML Activity Diagram
CS251 – Software Engineering Lectures 11 State Diagrams
Business System Development
Software Engineering Chapter 5 (Part 3) System Modeling Dr.Doaa Sami.
States.
Object Oriented System Design
Activity Diagrams.
States.
Appendix 3 Object-Oriented Analysis and Design
Presentation transcript:

Modeling Dynamic Behavior: State and Activity Diagrams

© Lethbridge/Laganière 2001 Chapter 8: Modelling Interactions and Behaviour2 State Diagrams A state diagram describes the behaviour of a system, some part of a system, or an individual object. At any given point in time, the system or object is in a certain state. —So it can respond in a specific way to an event. Some events will cause the system to change state. —In the new state, the system will behave in a different way to events. A state diagram is a directed graph whose nodes are states and arcs are transitions between states.

© Lethbridge/Laganière 2001 Chapter 8: Modelling Interactions and Behaviour3 State diagrams – an example tic-tac-toe game OTurn XTurn Tie OWin XWin

© Lethbridge/Laganière 2001 Chapter 8: Modelling Interactions and Behaviour4 States At any given point in time, the system is in one state. A state is represented by a rounded rectangle containing the name of the state. Special states: —A black circle represents the start state —A circle with a ring around it represents an end state A transition is a change of state in response to an event. The label on each transition is the event that triggers it. The system remains in a state until an event occurs that causes it to change state.

© Lethbridge/Laganière 2001 Chapter 8: Modelling Interactions and Behaviour5 after(30s) after(5s) after(25s) RedLight GreenLight YellowLight after(25s since exit from state RedLight) RedLight GreenLightChangeTriggered YellowLight after(5s) after(30s) vehicleWaitingToTurn GreenLightNoTrigger State diagrams and transitions

© Lethbridge/Laganière 2001 Chapter 8: Modelling Interactions and Behaviour6 State diagrams – an example with conditional transitions (states of a CourseOffering) addStudent(aStudent) Closed enrollment >= capacity cancel openRegistration Offered OpenEnoughStudents OpenNotEnoughStudents enrollment >= 5 addStudent(aStudent) closeRegistration cancel Cancelled

© Lethbridge/Laganière 2001 Chapter 8: Modelling Interactions and Behaviour7 Activities in state diagrams An activity is an event that occurs in a particular state. —It takes a period of time. —The system may transition out of the state when the activity completes. —Another outgoing transition may interrupt the activity before it completes. E.g., press button do: play chosen selection MusicPlaying ProposeSelection

© Lethbridge/Laganière 2001 Chapter 8: Modelling Interactions and Behaviour8 Actions in state diagrams An action takes place instantaneously - either during a transition, on entry to a state, or on exit from a state. An action should consume no noticeable amount of time Enter / start motor forward Enter / start motor backward Enter / stop motor Enter / stop motor openingCompleted closingCompleted pressButton Closing Open OpeningClosed

© Lethbridge/Laganière 2001 Chapter 8: Modelling Interactions and Behaviour9 Nested states and guards An entire state diagram can be nested inside a state (guards are conditions for entry). FirstSecondThird ReverseNeutral selectDrive reachThirdSpeed [driveSelected] dropBelowThirdSpeed reachSecondSpeed [driveSelected] dropBelowSecondSpeed [driveSelected] selectFirstselectSecondselectNeutral selectReverse selectFirstselectSecond

© Lethbridge/Laganière 2001 Chapter 8: Modelling Interactions and Behaviour10 State diagram – an example with substates addStudent(aStudent) openRegistration Offered EnoughStudents NotEnoughStudents enrollment >= 5 Open Closed enrollment >= capacity cancel closeRegistration Cancelled do: unregister students

© Lethbridge/Laganière 2001 Chapter 8: Modelling Interactions and Behaviour11 Activity Diagrams An activity diagram is an extended state diagram where: —The focus is on sequences of actions (rather than messages between objects). —The flow of events is clearly represented. —concurrent activities can be clearly represented. —most transitions are triggered by internal events, such as the completion of a computation. —interactions among different use cases can be visualized. —several classes are usually involved.

© Lethbridge/Laganière 2001 Chapter 8: Modelling Interactions and Behaviour12 Representing concurrency Concurrency is shown using forks, joins and rendezvous. —A fork has one incoming transition and multiple outgoing transitions. -Execution creates two concurrent threads. —A join has multiple incoming transitions and one outgoing transition. -The incoming transitions are separate threads. -If one incoming transition completes, a wait occurs until the other transitions complete. -The outgoing transition will be taken when all incoming transitions have completed. —A rendezvous has multiple incoming and outgoing transitions. -Once all the incoming transitions complete, all the outgoing transitions are initiated.

© Lethbridge/Laganière 2001 Chapter 8: Modelling Interactions and Behaviour13 Example activity diagram with concurrency Verify course not full Receive course registration request Check prerequisites Check special permission Complete registration [ok] [not ok]

© Lethbridge/Laganière 2001 Chapter 8: Modelling Interactions and Behaviour14 Swimlanes Often, the division of activities among the classes in an activity diagram can be clarified using swimlanes. Verify course not full Receive course registration request Check prerequisites Check special permission Complete registration [ok] [not ok] StudentCourseOffering

© Lethbridge/Laganière 2001 Chapter 8: Modelling Interactions and Behaviour15 Implementing Classes from Sequence and Activity Diagrams These diagrams are most useful for parts of the system that are most complex. —I.e. they’re not for every class Interaction, activity and state diagrams help you create a correct implementation. This is particularly true when a behaviour is distributed across several use cases. —E.g. a state diagram is useful when different conditions cause instances to respond differently to the same event.

© Lethbridge/Laganière 2001 Chapter 8: Modelling Interactions and Behaviour16 E.g., The Course and CourseOffering classes Class diagram ***** ****** * CourseOffering requestToRegister CourseRecord Course getPrerequisites getOfferings Schedule addCourse meetsPrerequisites addStudent

© Lethbridge/Laganière 2001 Chapter 8: Modelling Interactions and Behaviour17 E.g., Consider the Course class Three states for Course ‘id’: ‘offered’: offeringsPosted() && getOfferings(id) != null. ‘open’: offered == true && one of its CourseOfferings has enrollment < capacity ‘closed’ (all of its offerings are full, or it is not offered): offered == false || offered == true && all of its CourseOfferings have enrollment >= capacity

© Lethbridge/Laganière 2001 Chapter 8: Modelling Interactions and Behaviour18 The Course class public class Course { // The 1-many association with class courseOffering private Collection courseOffering = new HashMap(); // Course has one or more offerings private boolean isOffered; // … one or more offerings are not full private boolean isOpen; // … all offerings are full private boolean isClosed; } These can change whenever an addStudent or deleteStudent occurs for one of its offerings --- only one is really needed. This can change whenever the system state changes

© Lethbridge/Laganière 2001 Chapter 8: Modelling Interactions and Behaviour19 Check to see if a course needs closing public void closeCheck () { // The 1-many association with class courseOffering private Collection courseOffering = new HashMap(); isClosed = true; iterator it = new Iterator (courseOffering); while (it.hasMoreElements()) { courseOffering co = it.nextElement(); if (!co.isFull()) isClosed = false; } Note: this is rough code -- it shows only the skeleton of what’s needed. It will not compile!

© Lethbridge/Laganière 2001 Chapter 8: Modelling Interactions and Behaviour20 Adding a student to a CourseOffering public boolean addStudent(Student student) { if (!isFull()) // offering must not be full { // Some of the sequence diagram guides this logic Course course = this.getCourse(); if (student.getTranscript().meetsPrerequisites(course)) { // create a new course record and add this offering to // student’s schedule courseRecord.put(new CourseRecord(this, student)); student.schedule.addCourse(this); // Check for transition to ’closed' state if (courseRecord.size() >= capacity) course.closeCheck(); }