Modelling interactions and behaviour Adapted after : Timothy Lethbridge and Robert Laganiere, Object-Oriented Software Engineering – Practical Software.

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

Object-Oriented Software Engineering Visual OO Analysis and Design
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.
ESE Einführung in Software Engineering 7. Modeling Behaviour Prof. O. Nierstrasz.
UML (Sequence Diagrams, Collaboration and State Chart Diagrams) Presentation By - SANDEEP REDDY CHEEDEPUDI (Student No: ) - VISHNU CHANDRADAS (Student.
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.
1 Chapter 4 Dynamic Modeling and Analysis (Part I) Object-Oriented Technology From Diagram to Code with Visual Paradigm for UML Curtis H.K. Tsang, Clarence.
1 Chapter 4 Dynamic Modeling and Analysis (Part I) Object-Oriented Technology From Diagram to Code with Visual Paradigm for UML Curtis H.K. Tsang, Clarence.
Systems Analysis and Design in a Changing World, Fourth Edition
Essentials of interaction diagrams Lecture 23 & 24.
Chapter 8: Modelling Interactions and Behaviour
Modeling Dynamic Behavior: State and Activity Diagrams.
7M822 UML Interaction Diagrams 25 November 2010.
Modeling Dynamic Behavior: Sequence and Collaboration Diagrams.
SE-565 Software System Requirements More UML Diagrams.
An Introduction to Rational Rose Real-Time
1 Lab Beginning Analysis and Design 4 Completion of first version of use case diagram initiates the processes of analysis and design. 4 UML provides.
Unified Modeling Language
Object-Oriented Software Engineering Practical Software Development using UML and Java Chapter 8: Modelling Interactions and Behaviour.
UML Collaboration Diagram. Recap System Sequence Diagrams (SSD) UML for SSD Examples.
Class, Sequence and UML Model.  Has actors and use cases.
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.
1 Object-Oriented Modeling Using UML (2) CS 3331 Fall 2009.
Object-Oriented Software Engineering Practical Software Development using UML and Java Chapter 8: Modelling Interactions and Behaviour.
Interaction Models (2): Sequence Diagrams Extracted from textbook: Object Oriented Modeling and Design with UML M. Blaha, J. Rumbaugh 1.
© 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 1 UML Sequence Diagrams.
1 Modeling interactions and behavior Lecturer Dr. Mai Fadel.
UML diagrams What is UML UML diagrams –Static modeoing –Dynamic modeling 1.
Activity diagrams. Introduction ● Activity diagrams are a behavioural model that represent the dynamics of the system. ● An activity diagram is essentially.
7 Systems Analysis and Design in a Changing World, Fifth Edition.
Smith’s Aerospace © P. Bailey & K. Vander Linden, 2005 Interaction and Communication Diagrams Patrick Bailey Keith Vander Linden Calvin College.
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.
Sequence Diagrams Sequence; Interaction Diagrams Behavioral Diagrams
Object-Oriented Software Engineering Practical Software Development using UML and Java Chapter 8: Modelling Interactions and Behaviour UML Sequence Diagram.
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.
Object Oriented Analysis & Design & UML (Unified Modeling Language)1 Part VI: Design Continuous Activity Diagams State Diagrams.
CS212: Object Oriented Analysis and Design Lecture 34: UML Activity and Collaboration diagram.
Systems Analysis and Design in a Changing World, Fourth Edition
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.
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.
Chapter 3: Introducing the UML
7 Systems Analysis – ITEC 3155 The Object Oriented Approach – Use Cases.
1 7 Systems Analysis and Design in a Changing World, 2 nd Edition, Satzinger, Jackson, & Burd Chapter 7 The Object-Oriented Approach to Requirements.
Unified Modeling Language. What is UML? Standard language for specifying, visualizing, constructing, and documenting the artifacts of software systems,
UML Review: State Machines. Sept. 17, 2003Lecture 5: CS660 Fall Overview States Transitions Activities Modeling object lifeline Creating well-structured.
Object-Oriented Software Engineering Practical Software Development using UML and Java Chapter 8: Modelling Interactions and Behaviour.
Systems Analysis and Design in a Changing World, Fourth Edition
Chapter 11: Collaboration Diagram - PART1
Unified Modeling Language
Sequence Diagram.
CS251 – Software Engineering Lectures 11 State Diagrams
Business System Development
UML dynamic Modeling (Behavior Diagram)
UML Activity Diagrams & State Charts
UML Sequence Diagrams.
Princess Nourah bint Abdulrahman University
CIS 375 Bruce R. Maxim UM-Dearborn
Unified Modelling Language
UML Interaction diagrams
CIS 375 Bruce R. Maxim UM-Dearborn
Appendix 3 Object-Oriented Analysis and Design
Presentation transcript:

Modelling interactions and behaviour Adapted after : Timothy Lethbridge and Robert Laganiere, Object-Oriented Software Engineering – Practical Software Development using UML and Java, 2005 (chapter 8)

© Lethbridge/Laganière 2005 Chapter 8: Modelling Interactions and Behaviour2 8.1 Interaction Diagrams Interaction diagrams are used to model dynamic aspects of a software system They help you to visualize how the system runs. An interaction diagram is often built from a use case and a class diagram. —An interaction model shows a set of actors and objects interacting by exchanging messages.

© Lethbridge/Laganière 2005 Chapter 8: Modelling Interactions and Behaviour3 Interactions and messages Interaction diagrams show how a set of actors and objects communicate with each other to perform: —The steps of a use case, or —The steps of some other piece of functionality. The set of steps, taken together, is called an interaction. Interaction diagrams can show various types of messages exchanged between objects, including: »Simple procedure calls, »Commands issued by an actor through the user interface, »Messages exchanged over a network. One of the main objectives of drawing interaction diagrams is to better understand the sequence of messages.

© Lethbridge/Laganière 2005 Chapter 8: Modelling Interactions and Behaviour4 Elements found in interaction diagrams Instances of classes (objects) —Shown as boxes with the class and object identifier underlined Actors —Shown using the same stick-person symbol as in use case diagrams Messages —Shown as arrows from actor to object, or from object to object

© Lethbridge/Laganière 2005 Chapter 8: Modelling Interactions and Behaviour5 Creating interaction diagrams Since you need to know the actors and objects involved in the interaction, you should normally develop a class diagram and a use case model before starting to create an interaction diagram. Two kinds of diagrams are used to show interactions: —Sequence diagrams —Communication diagrams

© Lethbridge/Laganière 2005 Chapter 8: Modelling Interactions and Behaviour6 Sequence diagrams A sequence diagram shows the sequence of messages exchanged by the set of objects performing a certain task. The objects are arranged horizontally across the diagram. An actor that initiates the interaction is often shown on the left. The vertical dimension represents time; the top of the diagram is the starting point and time progresses downwards towards the bottom of the diagram. A vertical dashed line, called a lifeline, is attached to each object or actor. The lifeline becomes a box, called an activation box, during the period of time (called live activation period) when the object is performing computations. A message is represented as an arrow between activation boxes of the sender and receiver. —You give each message a label; it can optionally have an argument list and a response (return value). The complete syntax is as follows: response := message(arg,…) —A creation message is shown using a dashed line with the label ‘create’.

© Lethbridge/Laganière 2005 Chapter 8: Modelling Interactions and Behaviour7 Sequence diagrams – an example Sequence diagram showing a student registration process: The labels on the messages in the sequence diagram correspond to operations in the corresponding class diagram (given below). The reception of a message by an object causes one of its methods to be run. Sequence diagrams are useful for identifying the operations that have to be included in each class.

© Lethbridge/Laganière 2005 Chapter 8: Modelling Interactions and Behaviour8 Sequence diagrams – same example, more details This is a combined fragment (a UML 2.0 feature) It shows a subsequence of an interaction. ‘opt’ is a label indicating that it may or may not occur. [hasPrerequisite] is a Boolean condition which describes the circumstances when it will occur. This is a return action, indicating the moment when the computation (the execution of requestToRegister) ends. A return value can (optionally) be shown as a label on a return action.

© Lethbridge/Laganière 2005 Chapter 8: Modelling Interactions and Behaviour9 Sequence diagrams – an example with replicated messages In a sequence diagram you can show iteration using a combined fragment with label ‘loop’. The number of iterations is specified using the syntax: min.. max. 0.. numPurchases loop :Bill :Purchase:Item getSubtotal getUnitPrice computeTotal Message sent to numPurchase different Purchase objects Corresponding class diagram:

© Lethbridge/Laganière 2005 Chapter 8: Modelling Interactions and Behaviour10 Sequence diagrams – an example with object deletion If an object’s life ends, this is shown with an X at the end of the lifeline This diagram describes a possible interaction for cancelling a Booking in the airline system introduced in chapter 5.

© Lethbridge/Laganière 2005 Chapter 8: Modelling Interactions and Behaviour11 Communication diagrams A communication diagram (known as a collaboration diagram in UML 1.x) is an interaction diagram that: shows the objects in two dimensions (a graph with objects as vertices) uses sequence numbers to show the order of messages Communication diagrams and sequence diagrams use different layouts, but are very similar (in UML 1.x they are semantically equivalent). Communication diagrams are a bit less expressive than sequence diagrams. Combined fragments - introduced in UML 2.0 (2004) - are lacking in communication diagrams. (communication) linkmessage

© Lethbridge/Laganière 2005 Chapter 8: Modelling Interactions and Behaviour12 Communication and sequence diagrams Remark: In Rational Rose 2002 (which is based on UML 1.x), you can press F5 to switch between a communication diagram and a corresponding sequence diagram; the two representations of the interaction are isomorphic.

© Lethbridge/Laganière 2005 Chapter 8: Modelling Interactions and Behaviour13 Communication links A communication link (in a communication diagram) can exist between two objects whenever it is possible for one object to send a message to the other one. The classes of the two interacting objects can be connected by: —an association, or —a dependency.

© Lethbridge/Laganière 2005 Chapter 8: Modelling Interactions and Behaviour State Diagrams A state diagram describes the behaviour of a (sub)system, or an individual object. At any given point in time, the system or object is in a certain state. —Being in a state means that it will behave in a specific way in response to any events that occur. 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 where the nodes are states and the arcs are (labelled) transitions. A transition represents a change of state in response to an event, and is considered to occur instantaneously (that is, to take no time). —The label of a transition represents the event that causes the change of state.

© Lethbridge/Laganière 2005 Chapter 8: Modelling Interactions and Behaviour15 State diagrams – a first example State diagram of a tic-tac-toe (noughts and crosses) game: The initial state is represented as a filled black circle A final state is represented as a filled black circle surrounded by an unfilled circle A state is rendered as a rectangle with rounded corners containing the name of the state A transition is rendered as a (solid) arrow connecting two states (in this first example all transitions are unlabelled)

© Lethbridge/Laganière 2005 Chapter 8: Modelling Interactions and Behaviour16 Overview of state diagram AStateAnotherState event(args) [guard condition] / action In general, a State Transition Diagram (STD) includes: states transitions; the specification of a transition can (optionally) include: an event that causes the transition (with optional arguments), a guard condition given between square brackets (if there is more than one transition out of a state there must be mutually exclusive guard conditions on each transition), and an action, which is a non-interruptible behavior that occurs as part of a transition.

© Lethbridge/Laganière 2005 Chapter 8: Modelling Interactions and Behaviour17 Example: STD specification of a one-bit buffer A one-bit buffer is a (software or hardware) component which may hold a single bit. A one-bit buffer B may accept a bit at the input port (1); when holding a bit it may deliver it at the output port (2). B 1 2 B B(0)B(1) r1(0) s2(0)s2(1) r1(1) In the STD specification we use the following conventions: r1(b) = receive bit b at port 1 s2(b) = send bit b at port 2 The STD describes a finite state machine.

© Lethbridge/Laganière 2005 Chapter 8: Modelling Interactions and Behaviour18 State diagrams and formal specification B B(0)B(1) r1(0) s2(0)s2(1) r1(1) A State Transition Diagram (STD) gives an accurate description of the system’s behavior. The behavior of the one-bit buffer can be specified by the following process algebra equation [BW90]: B = r1(0). s2(0). B + r1(1). s2(1). B Here ‘.’ is the operator for sequential composition ‘+’ is the operator for non-deterministic choice. In case not just bits, but more generally, elements of some finite data set (d  )D are buffered we get the following equation: B =  d  D r1(d). s2(d). B

© Lethbridge/Laganière 2005 Chapter 8: Modelling Interactions and Behaviour19 State diagrams with elapsed-time transitions GreenLight YellowLight RedLight after(30s) after(25s) after(5s) The event that triggers a transition can be a certain amount of elapsed time. The STD given below illustrates the use of elapsed-time transitions to model the behavior of a simple traffic light.

© Lethbridge/Laganière 2005 Chapter 8: Modelling Interactions and Behaviour20 State diagrams – an example with conditional transitions This STD describes the behavior of instances of the CourseSection class. It includes two transitions triggered by conditions becoming true. For example, in the OpenNotEnoughStudents state a CourseSection object makes a transition to the OpenEnoughStudents state (in which the course can actually be taught) as soon as the (classSize >= minimum) condition becomes true. Remark: createRegistration is an action attached to the requestToRegister(...) event.

© Lethbridge/Laganière 2005 Chapter 8: Modelling Interactions and Behaviour21 Activities in state diagrams An activity is something that takes place while the system is in a state. —It takes a period of time. —An activity is shown inside the state itself, preceded by the string “do /”. —The system takes a transition out of the state in response to completion of the activity (if no other transition is triggered before by some event).

© Lethbridge/Laganière 2005 Chapter 8: Modelling Interactions and Behaviour22 State diagram – an example with activity State diagram for a jukebox illustrating an activity in a state. In the ProposeSelection state the system waits for the user to press a button, selecting some music. In the MusicPlay state the system plays the chosen music until it comes to an end. The system then takes a transition back to the ProposeSelection state.

© Lethbridge/Laganière 2005 Chapter 8: Modelling Interactions and Behaviour23 Actions in state diagrams An action is something that takes place effectively instantaneously —When a particular transition is taken (in this case the action is attached to an event) —Upon entry into a particular state -An entry action is shown inside the state, preceded by the string “entry /” —Upon exit from a particular state -An exit action is shown inside the state, preceded by the string “exit /” An action should consume no noticeable amount of time

© Lethbridge/Laganière 2005 Chapter 8: Modelling Interactions and Behaviour24 State diagram – an example with actions State diagram for a garage door opener pressButton Closed enter / stop motor Opening enter / start motor forwards do / run motor forwards Closing enter / start motor in reverse do / run motor in reverse Open enter / stop motor closingCompleted pressButton openingCompleted

© Lethbridge/Laganière 2005 Chapter 8: Modelling Interactions and Behaviour25 State diagram – an example with substates A state diagram can be nested inside a state. The states of the inner diagram are called substates. If two or more states have an identical transition, they can be grouped together in a superstate. Then, rather than maintaining two identical transitions (one for each substate) the transition can be moved to the superstate. The figure shows the behavior of instances of the CourseSection class, converted to use nested substates. It is now enough to show only one ‘cancel’ transition and one ‘requestToRegister’ transition.

© Lethbridge/Laganière 2005 Chapter 8: Modelling Interactions and Behaviour Activity diagrams An activity diagram is used to understand the flow of work that an object or a system performs. An activity diagram is a special kind of a state transition diagram, that shows the flow from activity to activity within a system. In an activity diagram the states are activity states and the flow of control passes immediately to the next state when the activity (of the current state) completes [BRJ99]. An activity state represents the performance of a non-atomic task within a state machine. An action state is a special kind of an activity state that cannot be further decomposed (the internal activity of an action state is a single atomic computation).

© Lethbridge/Laganière 2005 Chapter 8: Modelling Interactions and Behaviour27 Activity diagram – an example with action states initial state final state guard expression branch action state An activity diagram can use action states to show the flowchart of an imperative program.

© Lethbridge/Laganière 2005 Chapter 8: Modelling Interactions and Behaviour28 Activity diagram – an example with activity states Draw up an outline specification Construct prototype Check with user Deliver specification Refine prototype [User happy] [User requires change] An activity diagram can use activity states to show human activities, such as software processes. The figure shows an activity diagram for throwaway prototyping [Bel05]:

© Lethbridge/Laganière 2005 Chapter 8: Modelling Interactions and Behaviour29 Additional references [BW90] J.C. Baeten, W.P. Weijland. Process algebra. Cambridge University Press, [Bel05] D. Bell. Software Engineering for Students – a Programming Approach (4 th edition). Addison-Wesley, [BRJ99] G. Booch, J.Rumbaugh, I. Jacobson. The Unified Modeling Language User Guide. Addison Wesley, 1999.