Lecture 9 - Class Diagram and Interaction Diagrams
Lecture 9 - Class Diagram and Interaction Diagrams
Lecture # 9
CLASS DIAGRAM AND
INTERACTION DIAGRAMS
Class Diagram in UML
6
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
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
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
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
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
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.
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.