Lecture 4a ClassDiagram
Lecture 4a ClassDiagram
CONT.
The UML allows you
to handle some other important
Association multiplicity
questions about associations: “How many Cars may a
Person own?” “How many can they rent?” “How many
people can drive a given Car?”
Associations define the rules for how objects in each class
may be related. So how do you specify exactly how many
objects may participate in the relationship?
2
Association multiplicity
Summary list of the options for specifying multiplicity followed
by some examples.
Values separated by two periods (..) mean a range. For
example, 1..3 means between 1 and 3 inclusively; 5..10 means
between 5 and 10 inclusively.
Values separated by commas mean an enumerated list of
possibilities. For example, 4,6,8 means you may have 4 objects
or 6 objects or 8 objects of this type in the association.
Asterisk (*) when used alone means zero or more, no lower or
upper limit.
Asterisk (*) when used in a range (1..*) means no upper limit
—you must have at least one but you can have as many more
as you want.
3
Association class
Encapsulates information about an association.
4
Reflexive association
Reflexive association is a fancy expression that says objects in the same class can be related to one another. The
entire association notation you’ve learned so far remains exactly the same, except that both ends of the association
line point to the same class.
5
Qualified Association
6
Aggregation and Composition
Aggregation is a special type of association used to
indicate that the participating objects are not just
independent objects that know about each other.
Instead, they are assembled or configured together to
create a new, more complex object.
For example, a number of different parts are assembled to
create a car, a boat, or a plane.
Composition is used for aggregations where the life
span of the part depends on the life span of the
aggregate.
The aggregate has control over the creation and
destruction of the part. In other words, the member
object cannot exist apart from the aggregation.
7
Aggregation and Composition
> Players are assembled into a team. But if the Team is disbanded, the players
live on (depending of course on how well they performed).
> The Book example uses composition, the solid diamond. A Book is composed
of Chapters. The Chapters would not continue to exist elsewhere on their own.
They would cease to exist along with the Book.
8
Example
Problem statement:
Our Company maintains a group of race cars. Our cars use
some of our new 8-cylinder engines and new transmissions.
Once the engines are assembled, the pistons, carburetor, and
plugs cannot be swapped between engines due to changes
caused by the high temperatures.
“We want to keep records of the performance achieved by
each engine in each car and each transmission in
combination with each engine. Our drivers evaluate each car
to give us their assessment of the handling. We need a
system to track the configurations and the drivers’
assessments.”
9
Sample Solution
10
Generalization
Generalization is the process of organizing the properties of a set of
objects that share the same purpose.
A generalization is not an association.
11