Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
CSE Department
Faculty of Engineering
University of Mauritius
Overview
List the different relationships that
affect classes and objects
4
Link
A link shows that a relationship exists
between two objects. (A link relates two
objects that communicate.)
5
Link example
E.g. Shehzad Jaunbuccus works for UoM
works-for
Shehzad Jaunbuccus: UoM:Institution
Employee
Linked instances may be from different classes (as with :Employee and
:Institution).
6
Link – Same Class
7
Link - Connects an Instance to itself
A link is an instance of an
association.
8
Dependency
A dependency between two classes declares that a class
needs to know about another class to use objects of that
class.
9
Dependency (2)
The UserInterface and Student classes simply work together
at the times when the user interface wants to display the
student details.
10
Association
Associations are meaningful relationships between
classes.
Note: Try to find an active verb phrase that relates the two classes.
This enables others to understand your diagrams more easily.
13
Links and Associations (1)
Suppose a manager decides to assign a staff member contact
to each client then links between instances of StaffMember
and Client could be:
14
Links and Associations (2)
15
Links and Associations (3)
16
Multiplicity (Relating many Objects) -1
19
Link/Association Attributes (1)
Sometimes attributes do not seem to fit in any one
class.
20
Link/Association Attributes (2)
A: An attribute whose value depends on more than one class
instance will need a third class that holds that attribute.
21
Link/Association Attributes E.g.
A third class is designated ( an association class) by using a
dashed line to connect the new class to the association.
The figure shows the two classes—Client and Movie - in the rents
relationship. It then shows another class (Rents) that contains the
special attribute dayOfRental.
22
Link/Association Attributes Notes
The previous figure shows dependency between the Rents
class and the association named rents.
23
Aggregation
Aggregation is a strong form of association in which an aggregate is
made of components. Components are part of the aggregate.
Saying "The whole is greater than the sum of the parts" is true with
aggregation
Characteristics
25
Aggregation Example (1)
If you have a class such as
SalesRegion and you want to model
the SalesRegion and its parts (such
as office, RetailOutlet, etc), you use
aggregation.
28
Composition
Composition is used for aggregations where the life span of
the member object depends on the life span of the aggregate.
The aggregate not only has control over the behavior of the
member, but also has control over the creation and
destruction of the member.
In other words, the member object cannot exist apart from the
aggregate.
29
Relationship between association,
aggregation and composition
The diagram shows that composition is a subset of
aggregation, just as aggregation is a subset of
association.
32
Composition Example (3)
Example of
composition, a
strong form of
aggregation.
33
Composition v/s Aggregation (1)
The multiplicity provides some clues about the distinction
between aggregation and composition. On the project team
example, each employee may or may not be a member of a
project team (0..*).
Employees may exist independent from project teams. In
fact, an employee may simultaneously participate in many
project teams.
Aggregation is a weak association in that it allows the
members to participate or not participate or even participate
in other aggregations at the same time.
If you hear words like ―part of,‖ ―contains,‖ or ―owns,‖ then you
probably have an aggregation relationship.
If the parts are not shared, then you may have composition.
35
Composition vs Aggregation (3)
36
Further Aggregation and
Composition examples (1)
Consider a Timer System
Constructing the Timer by Association involves individually creating
the clock, counter, textbox and button objects and using the methods
to build up the required structure of connection among these objects.
37
Further Aggregation and
Composition examples (2)
With Aggregation/Composition the basic machinery of the timer
system is encapsulated inside another object, Stopwatch.
The public interface of the Stopwatch class provides methods that allow the timer
system to be manipulated as a whole. 38
Composition and Java
Composition does have a coding equivalent
in Java
if you had a class named Cat and a class named Dog, you
can create a generalization of both of those classes called
Animal
Phrases like ―is-a kind of" and ―is-a type of" are often used to
describe a generalization relationship between classes
40
Generalisation Example
The generalization relationship is shown with a solid
line with a closed arrow, pointing from the specific
class to the general class.
E.g. of the Cat to Animal relationship
Unlike associations,
generalization relationships are
typically not named and don't
have any kind of multiplicity.
41
Superclass
42
Subclass
A subclass is a class that contains some
combination of the features that are unique
to a subset of the objects defined by a
superclass.
45
Adding a new subclass (1)
Consider the following hierarchy.
46
Adding a new subclass (2)
After adding the new subclass WeeklyPaidEmployee
47
References
[1] Object Oriented Software Development Notes,
(UoM, Moodle)
48