object-Oriented Software Engineering Practical Software development using uml and Java Chapter 8: Modelling Interactions and behaviour www.oseng.com
Object-Oriented Software Engineering Practical Software Development using UML and Java Chapter 8: Modelling Interactions and Behaviour
8.1 Interaction Diagrams Interaction diagrams are used to model the 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 - The objective is to show how a set of objects accomplish the required interactions with an actor www.oseng.com O Lethbridge/Laganiere 2001 Chapter 8: Modelling Interactions and behaviour
© Lethbridge/Laganière 2001 Chapter 8: Modelling Interactions and Behaviour 2 8.1 Interaction Diagrams Interaction diagrams are used to model the 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. —The objective is to show how a set of objects accomplish the required interactions with an actor
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 several different types of communication e. g. method calls, messages send over the network These are all referred to as messages www.oseng.com O Lethbridge/Laganiere 2001 Chapter 8: Modelling Interactions and behaviour
© Lethbridge/Laganière 2001 Chapter 8: Modelling Interactions and Behaviour 3 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 several different types of communication. —E.g. method calls, messages send over the network —These are all referred to as messages
Elements found in interaction diagrams Instances of classes Shown as boxes with the class and object identifier underlined Actors use the stick-person symbol as in use case diagrams messages Shown as arrows from actor to object, or from object to object www.oseng.com O Lethbridge/Laganiere 2001 Chapter 8: Modelling Interactions and behaviour 4
© Lethbridge/Laganière 2001 Chapter 8: Modelling Interactions and Behaviour 4 Elements found in interaction diagrams • Instances of classes —Shown as boxes with the class and object identifier underlined • Actors —Use the stick-person symbol as in use case diagrams • Messages —Shown as arrows from actor to object, or from object to object
Creating instances diagrams You should develop a class diagram and a use case model before starting to create an interaction diagram. There are two kinds of interaction diagrams -Sequence diagrams -Collaboration diagrams www.oseng.com O Lethbridge/Laganiere 2001 Chapter 8: Modelling Interactions and behaviour
© Lethbridge/Laganière 2001 Chapter 8: Modelling Interactions and Behaviour 5 Creating instances diagrams You should develop a class diagram and a use case model before starting to create an interaction diagram. • There are two kinds of interaction diagrams: —Sequence diagrams —Collaboration diagrams
Sequence diagrams- an example Course section Student requestToRegister : Registration > addTo Schedule add ToRegistrationList Course CourseSection Registration Student getPrerequisite request To Register add ToSchedule add To RegistrationList hasPassedCourse www.oseng.com O Lethbridge/Laganiere 2001 Chapter 8: Modelling Interactions and behaviour 6
© Lethbridge/Laganière 2001 Chapter 8: Modelling Interactions and Behaviour 6 Sequence diagrams – an example requestToRegister addToSchedule > :Student :Registration :CourseSection addToRegistrationList * CourseSection * * requestToRegister Course Registration getPrerequisite Student addToSchedule hasPassedCourse addToRegistrationList
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 A vertical line, called a lifeline, is attached to each object or actor The lifeline becomes a broad box, called an activation box during the live activation period A message is represented as an arrow between activation boxes of the sender and receiver - a message is labelled and can have an argument list and a return value www.oseng.com O Lethbridge/Laganiere 2001 Chapter 8: Modelling Interactions and behaviour
© Lethbridge/Laganière 2001 Chapter 8: Modelling Interactions and Behaviour 7 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 initiatesthe interaction is often shown on the left. • The vertical dimension representstime. • A vertical line, called a lifeline, is attached to each object or actor. • The lifeline becomes a broad box, called an activation box during the live activation period. • A message is represented as an arrow between activation boxes of the sender and receiver. —A message is labelled and can have an argument list and a return value
Sequence diagrams same example, more details GUI Course Section a Student: Course Student I request ToRegister requestToRegister (astudent) as Prerequisite getPrerequsiter囗 sPassedcourse (prereq [hasPrerequisite > Registration add ToRegistrationList add ToSchedule I www.oseng.com O Lethbridge/Laganiere 2001 Chapter 8: Modelling Interactions and behaviour 8
© Lethbridge/Laganière 2001 Chapter 8: Modelling Interactions and Behaviour 8 Sequence diagrams – same example, more details requestToRegister (aStudent) addToSchedule aStudent: Student :Registration GUI :CourseSection requestToRegister :Course [hasPrerequisite] > prereq := getPrerequisite hasPrerequisite := hasPassedCourse(prereq) addToRegistrationList
Sequence diagrams an example with replicated messages An iteration over objects is indicated by an asterisk preceding the message name Bill Purchase Item for all PurchaselgetSubtotal ge uNitpRice ompu te Total Bill Purchase Item quantity pnce www.oseng.com O Lethbridge/Laganiere 2001 Chapter 8: Modelling Interactions and behaviour
© Lethbridge/Laganière 2001 Chapter 8: Modelling Interactions and Behaviour 9 • An iteration over objects is indicated by an asterisk preceding the message name * Purchase * quantity Bill Item price *[for all Purchase] getSubtotal :Bill :Item getUnitPrice computeTotal :Purchase Sequence diagrams – an example with replicated messages
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 Speci ficFlight Booking Passen gerRole cancelBookings cancel de lete fromltine ran de lete From Passen gerlist www.oseng.com O Lethbridge/Laganiere 2001 Chapter 8: Modelling Interactions and behaviour
© Lethbridge/Laganière 2001 Chapter 8: Modelling Interactions and Behaviour 10 • If an object’s life ends, this is shown with an X at the end of the lifeline Sequence diagrams – an example with object deletion cancelBooking deleteFromItinerary cancel :SpecificFlight :Booking :PassengerRole deleteFromPassengerList