Download Interaction and State Diagrams in Object-Oriented Software Engineering and more Slides Banking and Finance in PDF only on Docsity! Object-Oriented Software Engineering Practical Software Development using UML and Java Chapter 8: Modelling Interactions and Behaviour Docsity.com 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. Docsity.com Creating interaction 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 —Communication diagrams Docsity.com Sequence diagrams — an example
:CourseSection Student
1 1 T
! requestToRegister. 4 create ‘Re cistrati on
In ----===5 —_——_— 1
addToSchedule
addToRegistrationList
1
! I wv I
Course *! — CourseSection *| Registration (* Student
getPrerequisite() requestToRegister() addToSchedule()
addToRegistrationList() hasPassedCourse()
Docsity.com
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. Docsity.com 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 Docsity.com Communication diagrams — an example
:CourseSection
1: create
— >
=
3: addToRegistrationList
:-Registration
2: addToSchedule
——
:Student
Docsity.com
Communication diagrams Communication diagrams emphasise how the objects collaborate in order to realize an interaction • A communication diagram is a graph with the objects as the vertices. • Communication links are added between objects • Messages are attached to these links. —Shown as arrows labelled with the message name • Time ordering is indicated by prefixing the message with some numbering scheme. Docsity.com Other communication links 2. The receiving object is stored in a local variable of the sending method. - This often happens when the object is created in the sending method or when some computation returns an object . - The stereotype to be used is «local» or [L]. 3. A reference to the receiving object has been received as a parameter of the sending method. - The stereotype is «parameter» or [P]. Docsity.com Other communication links 4. The receiving object is global. - This is the case when a reference to an object can be obtained using a static method. - The stereotype «global», or a [G] symbol is used in this case. 5. The objects communicate over a network. - We suggest to write «network». Docsity.com How to choose between using a sequence or communication diagram Sequence diagrams • Make explicit the time ordering of the interaction. —Use cases make time ordering explicit too —So sequence diagrams are a natural choice when you build an interaction model from a use case. • Make it easy to add details to messages. —Communication diagrams have less space for this Docsity.com 8.2 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. —Being in a state means that it is 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 transitions. Docsity.com State diagrams – an example • tic-tac-toe game (also called noughts and crosses) Docsity.com States • At any given point in time, the system is in one state. • It will remain in this state until an event occurs that causes it to change 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 Docsity.com