You are on page 1of 21

CSE 422:

Advanced Software engineering


Lecture 7: Modelling Classes
Interactions and Behavior
Second semester 2021
What will you learn in this course?

• Review of Software and Software Engineering


• Object Orientation Concepts
• SW Developing Requirements
• Chapter 4: Modelling With Classes
• Modelling Classes Interactions and Behavior
• Testing and Inspecting to Ensure High Quality
• Using Design Patterns
• Focusing on Users and Their Tasks
• Architecting and Designing Software
• Basing Software Development on Reusable Technology
Modeling Classes Interactions and
Behavior
• An interaction model shows a set of actors and
objects interacting by exchanging messages.
• A behavior model shows how an object or system
changes state in reaction to a series of events.
• Classes Interactions and Behavior diagrams:
– Interaction diagram
• Sequence diagram
• Communication diagrams
– State diagram
– Activity diagram
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.
• messages exchanged over a network
• simple procedure calls
• commands issued by an actor through the user interface
• 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
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:
• Show how the classes work together to perform
the actor actions.
– Communication diagrams
• Show the messages sent between objects and
the order of sending messages.
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 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 response (i.e.
return) value. response:=message(arg,...)
Sequence diagrams – an example

• This example shows how the classes work together to


allow a student actor to register in a course;

TheThe
labels
labels
on the
on the
messages
messages
in interaction
in interaction
diagram
diagram
correspond
correspondtotooperations
operations(methods)
(methods)ininclass
classdiagram
diagram
Sequence diagrams – an example

• This example shows how the classes work together to


allow a student actor to register in a course;

Initial Registration object is created


as the interaction proceeds
objects

Note the difference between


Create interaction and others
others
Sequence diagrams – example more details

This is combined fragment marked as ‘opt ’.


▪ A combined fragment is a subsequence of an interaction that is special in some way
▪ The ‘opt’ label means that it may or may not occur

A Boolean condition, written within square brackets, describes the


circumstances when this special subsequence will occur
Sequence diagrams – an example with replicated
messages
• An iteration over objects is indicated by an asterisk preceding
the message name

This is combined fragment marked as ‘loop’.


▪ This combined fragment is used in case if a sequence of messages must be
repeated

The number of times to loop is


specified using the syntax:
min ….. max…...

This is represented when a


message being sent from an
object to itself
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
Communication diagrams

• A communication diagram shows several objects working


together.
• It appears as a graph with a set of objects and actors as the
vertices.
• A communication diagram is very much like an object
diagram except that, as we will discuss below, it shows
communication links instead of links of associations
• It also has much in common with a sequence diagram,
except that lifelines, activation boxes and combined
fragments are absent
Communication diagrams
• Communication links are added between objects (the line
connect the objects)
• Messages are attached to these links.
o Shown as arrows labelled with the message name and
optional arguments
• Time ordering is indicated by prefixing the message with
some numbering scheme, represents when order of the
messages.
Communication diagrams – same example, more
details
• More details are added to show prerequisites and
adding course to student schedule.
Communication links
– A communication link can exist between two objects
whenever it is possible for one object to send a
message to the other one.
– Several situations can make this message exchange
possible:
1. The classes of the two objects have an association between
them.
– This is the most common case.
– If all messages are sent in the same direction, then
probably the association can be made unidirectional.
2. The objects communicate over a network.
– Often written in the diagram as «network».
Other communication links
3. 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.
4. 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].
5. A reference to the receiving object has been received as a
parameter of the sending method.
– The stereotype is «parameter» or [P].
choose between using a sequence or
communication diagram
• Sequence diagrams
Sequence diagrams are often the better choice in the following four
situations:
1. To enable any reader to easily see the order in which messages
occur.
2. When making interaction model from a use case. Use cases
already have a sequence of steps; sequence diagrams expand on
these to show which objects are involved.
3. When you need to show details of messages, such as parameters
and return values. communication diagrams has no space for all
these details.
4. When you need to show loops, optional sequences and other
things that can only be properly expressed using combined
fragments.
choose between using a sequence or
communication diagram
• Communication diagrams
– when you are deriving an interaction diagram
from a class diagram.
➢ communication diagrams are effectively object diagrams
with communication links instead of association links.
– Communication diagrams can in fact be used to
help validate class diagrams
– a communication diagram might suggest, for
example, that you should add a new association in
order to make the interaction possible.
Thanks

See you next week

You might also like