2. Agenda
UML Modeling 2022 2
What will we learn
today?
• Working with Relationships
• Understanding
Aggregations, compositions,
interfaces & Realizations
3. Acknowledgements
Material for the Lectures are derived from a
variety of sources, including:
• Joseph, Schmuller. "Sams Teach Yourself
UML in 24 Hours."
• Object-Oriented and Classical Software
Engineering, Sixth Edition, WCB/McGraw-Hill,
2005 Stephen R. Schach
• UML resource page http://www.uml.org/
UML Modeling 2022 3
5. Working with
Relationships
A class describes a group of objects with:
similar properties (attributes).
Common behavior (operations)
common relationships to other objects
and common meaning (“semantics”).
Example:
employee: has a name, employee# and department;
an employee is hired, and fired; an employee works
in one or more projects.
UML Modeling 2022 5
6. Instances
An instance represents a phenomenon.
The name of an instance is underlined and can contain the class of the
instance.
The attributes are represented with their values.
Uml Modeling 2022 6
zone2price = {
{‘1’, .20},
{‘2’, .40},
{‘3’, .60}}
tarif_1974:TarifSchedule
7. Types of relationships
Relationships are basically connections between classes to fill out a
picture.
A way to related classes to one another.
Types of Relationships
Associations
Constraints on Associations
Qualified Associations
Reflexive Associations
Inheritance
Generalizations
Dependencies
Uml Modeling 2022 7
8. Association
When classes are connected conceptually, it’s called association
Associations denote relationships between classes.
Example:
Association between a player and a team.
It can be described as “A player plays on the team”
A filled triangle used to point appropriate direction of the association.
Uml Modeling 2022 8
9. Association
When one class associates with another, each one usually plays a role
within that association.
You can show each class’s role by writing it near the line next to the
class.
Or
Uml Modeling 2022 9
10. Constraints on Association
Sometimes an association between 2 classes must follow a rule. That
rule is called Constraint.
It is indicated by putting a constraint near the association line.
Example
A bank teller serves a customer. But each Customer is served in the order
in which he/she appears in the line. That’s a constraint.
Uml Modeling 2022 10
11. Constraints on Association
Another type of constraint is the (or) relationship. Signified by (or) on a
dashed line that connects 2 association lines.
Example
A high school student choosing either an academic course of study or a
commercial one as shown in figure.
Uml Modeling 2022 11
12. Association Classes
When an association have attributes and operations, just like a class, It’s
called association class.
It is visualized in the same way as a regular class and a dashed line is
used to connect it to the association line.
Uml Modeling 2022 12
13. Multiplicity of Association
The number of objects from one class that relate with a single object in
an associated class.
The ability to show how many objects are involved in the association.
One class can relate to another class in many relationships. That are
One-to-one relationship
One-to-many relationship
Many-to-one relationship
Many-to-many relationship
Uml Modeling 2022 13
14. UML classes and association in MHC-
PMS
UML Modeling 2022 14
16. Qualified
Associatio
n
A qualified association has a qualifier that is
used to select an object (or objects) from a larger
set of related objects, based upon the qualifier
key. Informally, in a software perspective, it
suggests looking things up by a key, such as
objects in a HashMap.
Example
For example, if a ProductCatalog contains
many ProductDescriptions, and each one can be
selected by an itemID
Uml Modeling 2022 16
17. Reflexive
Associatio
n
When a class is in an association with itself, it’s
called Reflexive association.
When a class have object that plays a variety of
roles.
For example, A carOpponent can be either a driver
or a passenger.
Uml Modeling 2022 17
18. Inheritance
One class can inherit attributes and operations from another class (Super
class).
Uml Modeling 2022 18
An inheritance hierarchy in an animal kingdom
19. Generalization
Generalization is an everyday technique that we use to manage complexity.
Rather than learn the detailed characteristics of every entity that we experience,
we place these entities in more general classes (animals, cars, houses, etc.) and
learn the characteristics of these classes.
This allows us to infer that different members of these classes have some common
characteristics e.g., squirrels and rats are rodents.
In modeling systems, it is often useful to examine the classes in a system to see if
there is scope for generalization. If changes are proposed, then you do not have to
look at all classes in the system to see if they are affected by the change.
Uml Modeling 2022 19
20. Generalization
In object-oriented languages, such as Java, generalization is implemented using the
class inheritance mechanisms built into the language.
In a generalization, the attributes and operations associated with higher-level
classes are also associated with the lower-level classes.
The lower-level classes are subclasses inherit the attributes and operations from
their super classes. These lower-level classes then add more specific attributes and
operations.
Uml Modeling 2022 20
26. Aggregation
A class consists of number of component classes. That special type of
relationship is called Aggregation.
Components and classes are in part-whole association.
Represented by a line between component and the whole with an open
diamond adjoining the whole.
Weak type of association.
Example:
A home computer system is an aggregation that’s consists of a CPU box, a
keyboard, a monitor, a CD-ROM drive, a modem, one-or-more hard drives,
a disk driver, printer and some speakers.
Uml Modeling 2022 26
29. Constraints on Aggregation
Sometimes set of possible components in an aggregation fall into an Or
relationship.
For example, in a restaurant a meal consists of salad or soup along with
main course and desert.
To model such problem, you will use a constraint representing with a
dotted line connecting two part-whole lines.
Uml Modeling 2022 29
30. Composites
A strong type of aggregation.
Each component can belong to just one whole.
For example, the composites of coffee table are the tabletops and the
legs, makes a composition.
Represented by a line between component and the whole with a filled
diamond.
Uml Modeling 2022 30
31. Composite
Structure
Diagram
One way to show components of class is
composition. However, if we want to show
internal structure of class, we use
composite structure diagram using
UML2.0
Uml Modeling
2022 31
32. Composite Structure Diagram
Example:
Suppose you are creating a
model of a shirt.
The composite structure
diagram focuses on the shirt
and its internal structure.
Uml Modeling 2022 32
33. Interfaces and Realizations
An interface is a set of operations
that specifies some aspect of a
class’s behavior and it’s a set of
operations that a class present to
other classes.
Class rectangle symbol that
contains the keyword «interface».
2022 Uml Modeling 33
Symbol
34. Interface
Example:
Every time you use a washing machine,
you don't rip it apart to get to the underlying
circuitry so that you can turn it on and set
the time parameters. You get the washing
machine to perform those operations by
turning a control knob.
The control knob, an interface to a
washing machine, allows you to get the
washing machine to carry out some of the
washing machine's operations
Another way to represent a class and an
interface is with a small circle connected by
a line to the class.
Uml Modeling 2022 34
35. Realization
The realization is a relationship between two objects, where the
client (one model element) implements the responsibility specified
by the supplier (another model element).
The realization relationship can be employed in class diagrams
and components diagrams.
The realization relationship does not have names.
It is represented by a dashed line with a hollow arrowhead at one
end that points from the client to the server.
Interface Realization
Interface realization is a kind of specialized relation between the
classifier and the interface. In interface realization relationship,
realizing classifiers conforms to the contract defined by the
interface.
Uml Modeling 2022 35
36. Inheritance vs Realization
Inheritance
Inheritance is like a relationship
between a parent and a child.
The parent passes on physical
attributes (eye color, hair color,
and so on) to the child, and the
child also takes on behaviors
from the parent
Uml Modeling 2022 36
Realization
Realization is something like the
relationship between a teacher
and a student
The teacher doesn't pass on any
physical attributes to the student,
but the student learns behaviors
and procedures from the teacher.
37. Interfaces Everywhere
A class can realize more than one
interface, and an interface can be realized
by more than one class.
2022 Uml Modeling 37
To model interaction with a class through its
interface, use a dependency symbol.
UML 2.0's "ball-and-socket" notation for modeling
interaction through an elided interface symbol.
38. Interfaces and ports
A port is an access point that
the mouse plugs into.
Your computer also has a
serial port, a parallel port, and
one or more USB ports.
These ports are the points
through which the computer
interacts with its environment.
In the figure the port symbol
is a small square on the
border of the class icon, and
the square is connected to
the interface.
Uml Modeling 2022 38
39. Visibility
Visibility applies to attributes or
operations and specifies the extent to
which other classes can use a given
class's attributes or operations (or an
interface's operations).
Three levels of visibility are possible.
1. At the public level, usability extends
to other classes.
2. At the protected level, usability is
open only to classes that inherit
from the original class.
3. At the private level, only the original
class can use the attribute or
operation.
Uml Modeling 2022 39
40. Scope
Scope is another concept relevant to attributes and operations and how
they relate across a system.
Two kinds of scope are possible.
1. In instance scope, each instance of a class has its own value for the
attribute or operation.
2. In classifier scope, only one value of the attribute or operation exists
across all instances of the class.
A classifier-scoped attribute or operation appears with its name underlined.
This type of scoping is usually used when a specified group of instances
(and no others) must share the exact values of a private attribute. Instance
scoping is by far the more common type of scope.
Uml Modeling 2022 40
How to represent.
Many to many: For example, a many-to-many relationship exists between customers and products: customers can purchase various products, and products can be purchased by many customers.