100% found this document useful (1 vote)
121 views29 pages

Lecture 9 - Class Diagram and Interaction Diagrams

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
121 views29 pages

Lecture 9 - Class Diagram and Interaction Diagrams

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 29

32

Lecture # 9
CLASS DIAGRAM AND
INTERACTION DIAGRAMS
Class Diagram in UML
6

▪ The class diagram is a static diagram. It represents


the static view of an application.

▪ Class diagram is not only used for visualizing,


describing and documenting different aspects of a
system but also for constructing executable code
of the software application.
Essentials of UML Class Diagrams
6

 The main symbols shown on class diagrams are:


 Classes
◼ represent the types of data themselves
 Associations
◼ represent linkages between instances of classes
 Attributes
◼ are simple data found in classes and their instances
 Operations
◼ represent the functions performed by the classes and their instances
 Generalizations
◼ group classes into inheritance hierarchies
Classes
7

 A class is simply represented as a box with the name of the class


inside
 The diagram may also show the attributes and operations

 The complete signature of an operation is:

operationName(parameterName: parameterType …): returnType


Associations and Multiplicity
8

An association is used to show how two classes are related to each
other
 Symbols indicating multiplicity are shown at each end of the
association
Labelling associations
9

 Each association can be labelled, to make explicit the nature of


the association
Analyzing and validating associations
10

 Many-to-one
◼ A company has many employees,
◼ An employee can only work for one company.
◼ This company will not store data about the moonlighting activities
of employees!
◼ A company can have zero employees
◼ It is not possible to be an employee unless you work for a
company

Employee worksFor 1 Company


*
Analyzing and validating associations
11

 Many-to-many
◼ An assistant can work for many managers
◼ A manager can have many assistants
◼ Assistants can work in pools
◼ Managers can have a group of assistants
◼ Some managers might have zero assistants.
◼ Is it possible for an assistant to have, perhaps temporarily,
zero managers?
Assistant * 1..** Manager
supervisor
Analyzing and validating associations
12

 One-to-one
◼ For each company, there is exactly one board of directors
◼ A board is the board of only one company
◼ A company must always have a board
◼ A board must always be of some company

1 1
Analyzing and validating associations
13

Avoid unnecessary one-to-one associations

Avoid this do this


Generalization
16

Specializing a superclass into two or more subclasses


 A generalization set is a labeled group of generalizations with a
common superclass
 The label (sometimes called the discriminator) describes the
criteria used in the specialization
More Advanced Features: Aggregation
23

 Aggregations are special associations that represent ‘part-


whole’ relationships.
◼ The ‘whole’ side is often called the assembly or the aggregate
◼ This symbol is a shorthand notation association named isPartOf
When to use an aggregation
24

As a general rule, you can mark an association as


an aggregation if the following are true:
 You can state that
◼ the parts ‘are part of’ the aggregate
◼ or the aggregate ‘is composed of’ the parts
Composition
25

 A composition is a strong kind of aggregation “is entirely made of”


◼ if the aggregate is destroyed, then the parts are destroyed as
well
Class diagram example
Interaction Diagrams
33

 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
34

 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
35

 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
36

 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
Sequence diagrams – an example
Sequence diagrams
38

 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.
Sequence diagrams –
39
same example, more details
Sequence diagrams –
an example with object deletion
40

 If an object’s life ends, this is shown with an X at the end of the


lifeline
Communication diagrams – an
41
example
Communication diagrams
42

 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.
Communication diagrams –
43
same example, more details
How to choose between using a
44
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
How to choose between using a
45
sequence or communication diagram
 Communication diagrams
 Can be seen as a projection of the class diagram
◼ Might be preferred when you are deriving an interaction
diagram from a class diagram.
◼ Are also useful for validating class diagrams.
Class Activity–

We are after a system that controls a recycling machine for returnable bottles
and cans. The machine will allow a customer to return bottles or cans on the
same occasion.
When the customer returns an item, the system will check what type has been
returned. The system will register how many items each customer returns and,
when the customer asks for a receipt, the system will print out what he
deposited, the value of the returned items and the total return sum that will be
paid to the customer.
The system is also be used by an operator. The operator wants to know how
many items of each type have been returned during the day. At the end of the
day, the operator asks for a printout of the total number of items that have
been deposited in the machine on that particular day. The operator should
also be able to change information in the system, such as the deposit values of
the items. If something is amiss, for example if a can gets stuck or if the receipt
roll is finished, the operator will be called by a special alarm signal.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy