Professional Documents
Culture Documents
1
This unit introduces the parts of UML needed to build
moderately sophisticated structural models.
From the basic notation for classes and associations, you will
develop more precise notations such as qualified
associations.
Note that: All SAQs and Exercises in this unit are required.
2
This section introduces the main modelling elements that you will find in a
domain structural model, also known as the conceptual model, which
presents a view of the static structure of the problem domain
With an understanding of the domain and its structure, you can build a
structural model that is an acceptable solution to the problem modelled by
the requirements – this is called an analysis structural model, or simply
an analysis model .
The main difference between the conceptual and the analysis models is
that the former represents entities from the domain and the latter entities
from the software solution.
Both are class models describing the objects and the relationships
between them.
3
A class model is a static model that describes the
objects and the relationships that are needed
between them to implement the required
functionality.
Models are always built for a purpose.
To decide if the model built is adequate for the
purpose you need a domain expert.
Domain expert: a person who understands the
relevant part of the application domain rather than
the technology used to automate it.
4
The agile modelling principles are particularly
relevant when thinking about how much precision
and correctness should go into drawing diagrams.
They stress that modelling is not the ultimate goal,
software is (Ambler, 2002).
◦ Lightness and simplicity take precedence over
completeness and complexity.
◦ Models should only be followed while they are of use.
◦ Ease of change and adaptability also need to be part of the
modelling process.
5
The search for classes
The first step in building a class model is to identify objects in the
problem domain
We look first for objects because objects are instances of the classes,
they are an excellent source of candidate classes.
6
To identify the classes:
A list of nouns makes an excellent starting point.
7
We should pay particular attention to events.
Will an instance of that kind of event have state,
behavior and identity that are significant in the
problem domain?
A loan of a book from a friend might not be worth
modeling, for example, but a bank loan is
significant.
◦ A bank loan must be paid back and it attracts interest so that you
pay back more than the original loan.
In all cases, you should clear up any ambiguity
with a domain expert or the users themselves.
8
Classes and properties
A class usually have properties that are important such as:
◦ Attributes: properties of objects.
◦ Associations: properties represent relationship between classes.
9
A class describes all possible objects of that type, defining
what the objects have in common.
10
A class model:
11
An object model:
12
An object diagram:
is a visual representation of an object model, showing a
snapshot of the system at some point in time.
13
Figure: An Object diagram of a hotel system
14
Why do we need Object diagrams?
15
A class diagram:
is a visual representation of a class model.
represents what all possible instances of the class
have in common.
16
A class diagram:
17
Attributes are properties of classes.
Attributes have values in objects (shown in object diagrams).
Attributes define the state of an object at any one time.
Example: attributes in the figure are: enSuite, floor and dailyRate.
A. Multiplicity;
B. Association names and role names;
C. Assumptions about meaning;
D. Navigation expressions;
E. Association between pair of classes;
F. Association between a class and itself.
21
A. Multiplicities
22
The general form for multiplicities uses
two integers to express the range of
allowable values: min..max
In the given figure; the symbol * is used in
place of the second integer when there is
no upper limit to the allowable values.
◦ The range 1..* means ‘1 or more’.
The symbol * on its own can be used
instead of 0..*, which means ‘0 or more’ –
often read as many.
You can have several ranges in a
multiplicity expression separated by Figure: Annotation for Association
commas.
◦ The expression 0,2..* means that there can
be either no associated objects or two or
more.
23
In the given diagram:
Location association:
Each room is located in one
hotel.
Each hotel has a t least 1 or at
most 99 room
Reservation association:
Each hotel has zero or more
potential guests
Each guest is either reserved in
hotel or no hotel reservation is
done.
Occupancy association:
Each room is either unoccupied
or occupied by one guest Figure: Examples of multiplicities with role names
Many guests occupied the room
in the past
24
B. Association names and role names
UML provides two mechanisms for naming associations:
25
2. Placing an association name in the middle of the
association line:
Association names are usually verbs.
UML allows a little black triangular arrowhead to be added
to the association name to indicate direction of reading.
26
C. Assumptions about meaning
It is important to give a symbol precisely the meaning that is
defined, rather than to make assumptions and read some other
interpretations.
The model in the figure says that each Person has a single
associated birthCity and a single associated workCity.
If the model had not included a workCity but had mentioned
only the birthCity, there is a strong possibility that you would
have used your knowledge to assume that the model would not
allow the birth city to change during the lifetime of a person.
28
Examples on navigation expression from the hotel models:
jack refers to Guest object (starting object)
29
In the given figure:
f27 refers to an object of the class
File.
f27.name will refer to the name attribute
of that specific object.
f27.component refers to the
Directory object d4.
f27.component.disk refers to the
disk attribute of the d4 object of the
class Directory.
Note that if there is no role name at the
other end of an association, you can use
the name of the class at that end of the
association, but with the first letter in
lower case; for example, instead of
f27.component we could have written Figure: Role names in (a) class diagram and (b)
f27.directory. object diagram
30
E. Several associations between a pair of classes
There can be more than one association between any two classes.
33
Solution
34
Summary of section
35
Interpreting Attributes
36
The conceptual model records attributes of classes that will be
familiar to a domain expert.
For example, a hotel manager will be familiar with the daily rate
for a room and whether or not it is occupied.
For instance, daily rates for rooms involve money, and you can
use a true/false (Boolean) expression to represent the
occupancy of rooms.
37
Importance of time
38
If the aim is to know which books are currently on loan, the association
will need to be broken when the member no longer possesses the book.
If you want to record which members have borrowed which books in the
past, the association should never be broken.
In this case, you probably need two associations, with roles such as
currentLoans and pastLoans as in the figure.
39
Aggregation and composition
40
Aggregation and composition
41
Aggregation and composition
Example:
A university owns various departments, and each department has a
number of professors.
A University can be seen as a composition of departments.
◦ If the university closes, the departments will no longer exist.
Departments have an aggregation of professors.
◦ the professors will continue to exist even if departments are no longer available.
In addition, a Professor could work in more than one department, but a
department could not be part of more than one university
43
Navigability: possibility to reach objects in one class from objects in an
associated class.
This could be represented by using an arrowhead at one or both ends of
an association.
Navigability specifies the direction of potential messages between
objects of related classes (associated classes).
The notion of navigability is mainly of use during implementation, when
you have to decide how to write the code that represents an association.
If navigability can be restricted to one direction only (which is not always
possible), the code will usually be simpler.
44
The figure shows that an Invoice can send a message to an
InvoiceLine, but not the other way round
Navigability means that it is possible to identify (or ‘reach’) objects in one
class from objects in an associated class.
The usefulness of this idea is realized during implementation, when
navigability in one direction alone (unidirectional navigability) can lead to
simpler code.
45
Qualified association
Suppose that one of your classes has an attribute that acts as a unique
identifier. It can be modeled using a qualified association.
A qualified association is an association at one end of which there is a
qualifier, consisting of one or more attributes.
The values of the attributes (taken together) uniquely identify the objects in the
class at the other end of the association.
The advantage of this approach is that you have put more information into the
model.
In UML, a qualifier is considered to be an attribute of an association.
It tells you about a property of the concept that relates the classes at the ends of
the association.
46
The figure shows a qualified association. The accountNo attribute has been moved out of
the Account class and has become a qualifier.
The qualifier is represented by a rectangular box at the far end of the association from the
class that the qualifier is an attribute of.
You can now read the model as saying that for a given combination of a bank and an
account number there is either one associated account or none.
It tells you something extra about the Bank–Account association.
48
An association class imposes the restriction that there can be
at most one instance of the class per pair of objects.
The figure means that for EACH link from an instance of Store
to an instance of Item, there exists one instance of the
association class (Inventory) with the attributes
quantityInStore and price, meeting the requirement.
50
Example:
The family has children.
By using the age attribute you could figure out (derive) those children that
are teenagers (between 13-19), and children who are still living at home.
You have seen in this section that class models are limited because they
only show the overall structure of a proposed system. That is, a class
model records the elements (classes) of a system and their relationships,
but does not show the importance of time.
Other techniques can greatly increase the precision and rigour of models.
◦ The navigability of an association can be used to indicate whether it is
possible to traverse an association to obtain the object or set of objects
of a given class.
◦ Qualified associations capture the uniqueness of some means of
identifying objects, as in the case of account numbers in a bank.
◦ It is possible to show additional, derived associations that are deducible
from other associations in a class diagram.
52
Generalisation/specialisation is a relationship between two types.
If type B specialises type A, an instance of B has all the features of an instance of
A but also has additional features special to type B.
In this case, B is a specialisation of A and A is a generalisation of B.
The figure illustrates the concepts of specialisation and generalisation.
There are some general properties and behaviour shared by all trees: they all
have leaves and they tend to grow upwards (and outwards).
Oak and pine are two specific kinds of tree that have properties specific to the
type of tree.
For example, they have differently shaped leaves.
Their behavior is also different: an oak tree drops
its leaves in autumn and grows new ones in the
following spring, whereas a pine tree keeps its
needles all year round.
‘Tree’ is therefore a generalisation of ‘oak’ and
‘pine’, while ‘oak’ and ‘pine’ are specialisations
Figure: Different kinds of tree
of ‘Tree’.
53
Superclasses and subclasses
54
You have an Account class and
want to define a SavingsAccount
class, with operations: credit,
debit, getBalance and
addInterest.
A SavingsAccount really is an
Account;
It is just a special form of Account
that can also handle interest.
In a class model specialisation is
indicated by a line with an open
arrowhead at the superclass end of
the line.
55
The figure is a model for representing the fact that children
attend a school and that adults are allocated to a tax office.
It uses two different subclasses of Person and puts the
aspects that differ into those subclasses.
56
Interfaces
10/17/2017 57
Figure : Another specialisation of Account
10/17/2017 58
Levels of specialisation
Below given figure represents a word-processed document
containing various parts that are specialised at two levels
60
Example:
61
Solution:
62
Summary of section
63
A constraint defines a restriction that must be satisfied in
any subsequent implementation.
64
Constraints on classes
In UML, you can attach a constraint to a class by putting it within curly
braces, as shown in the figure.
You can use English (most common) to write constraints in curly brackets or
Object Constraint Language (OCL), which is a formal notation in UML that
combines logical expressions with set notation.
66
Constraints across associations
Constrains could be added to association either formally or informally.
67
Constraints across associations
Formal way: using special notation in curly brackets: {subset} and {xor}
notations.
68
Constraints across associations
2. {xor}: is used to specify that an instance of the class must participate in
exactly one of the associations grouped together by the {xor} constraint.
In the figure the {xor} constraint is used to express the fact that although
the class Customer has two different associations, one with
SavingsAccount and the other with GoldAccount, any particular
instance of Customer will only have one of these associations.
To capture the common invariant that a child must be younger than both
father and mother, we have written the following invariant for the class
Child:
71
Finding invariants by considering loops in associations
Associations in a class model can form loops.
72
Finding invariants by considering loops in associations
The problem: this model does not reflect the fact that the employee can't
be both the driver and the guard for the particular train.
73
Finding invariants by considering loops in associations
The diagram can be modified by adding a constraint as shown below:
74
Summary of section
In the early stages of analysis, class models may be too general because
they are not constrained by the rules that govern the domain in question.
Most models require constraints to limit them to valid configurations, and
there are various notations for expressing them.
◦ In UML, attributes of a class can be constrained using an invariant in
order to express one of the rules of the domain.
◦ UML provides a number of ways of expressing constraints on
associations. There are special notations such as {xor}, as well as the
formality of OCL or the informality of natural language. When choosing
which notation to use, you should consider the skills of those who will
read the model.
◦ Associations in a class model can form loops. Such loops may be
totally independent, but can often hide a restriction that should be
expressed as a constraint.
75
Unit Summary
On completion of this unit you should be able to:
76