Unit 2.2

You might also like

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 25

Topics to be covered

 N-ary association.
 Aggregation.

1
Objectives
The objective is to learn the following concepts..

1. Associations
2. Recursive associations, attributed association
3. Association constraints
4. Qualified & derived associations
5. UML – aggregation

2
Associations

 An association shows a two-way relationship between


objects (instances) of two or more classes.

 A particular instance of an association is often called a


link.

 Associations between classes are required if the objects


need to communicate.

 Associations are often named, and have role-names for


each side of the link.

3
More on Associations

Association Name

Car Person
Vehicle Registration
model name
year registeredCar owner age
# of doors address

Roles Names

4
More on Associations

 Simple example:
 An association has a name and a numerical specification
(multiplicity indication) of how many objects on one side of
the association are connected with how many objects on the
other side.
 Associations are called use relationships.

employs 0..*
Company Person
Employer Employee
5
More on Associations

 Recursive association: A class has a relation with itself.


 It is also possible to model associations that are valid only
temporarily “stereotype or temporary”
 Constraints may be used to restrict the relation under
specific aspects.
 A role name describes how the object is seen by the
opposite object in the association.
 An association can be described in more detail by means of
constraints, tagged values, and stereotypes.
 Stereotypes are noted before or above the relation name,
constraints, and tagged values after or below the name.
6
More on Associations

 Directed association is a one-way association, in which


one side knows the other, but not vice versa.
 Multiplicity Specification:
 1 exactly one
 0, 1 zero or one
 0..4 between zero and four
 3, 7 either three or seven

7
More on Associations

 More multiplicity specifications:


 0..* greater than or equal to zero (default)
 1..* greater than or equal to one
 0..3, 7, 9..* between zero and three, or exactly
seven, or greater than or equal to nine.

8
More on Associations

 Recursive associations are associations in which one


class is involved.

Employee

name
office clerk
staffNo
roomNo *

manager 1

leads

reports to

9
N-ary Association

 An n-ary association is like a common (binary)


association, except that more than two association roles
involved in it.

N-ary
association
Class1 Class2

Ternary
association
Class3

10
More on n-ary Association

Reservation
Train Seat
1 1..*
date carriageNo
trainNo seatNo

1..*
Passenger
name Ternary
title association

11
Association Class

Server Connection Client

Connection

baudRate • These attributes don’t belong


protocol in either the Client or Server
wireType class.
• They are attributes of the
disconnect
rerouteLink connection itself.

• The association class can have behaviors as well as attributes.

12
Aggregation & Composition

1. Aggregation
2. Composition

 Aggregation is a special form of association.


Aggregation is a kind of association in which an aggregate
object is made of constituent parts.

 Aggregation is used when the relationship is “part/whole”


or “contains/is-part-of”

13
Aggregation

 Special diamond symbol used on “whole” side to indicate


aggregation.

 Aggregation is an anti-symmetric that is, if A is part of B,


then B is not part of A.

 DO NOT confuse aggregation with generalization

14
Aggregation

Indicates
aggregation
* *
LawnMower

* *

1 1 * 1

Blade Engine Wheel Deck

Aggregation is a kind of association in which an aggregate


object is made of constituent parts.

15
Aggregation contd..
 Aggregation is a strong form of an association in which an
aggregate object is made of constituent parts.
 Constituent are part of the aggregate.
 It is made of several lesser objects. For e.g.
Lawn mower consists of a blade, an engine, many wheels and a
deck.
 Lawn mower is an assembly and parts are constituents.
 Lawn mower to blade is one aggregation.
 Lawn mower to engine is another aggregation and so on.
 We define each individual pairing as an aggregation so that we
can specify the multiplicity of each constituent part within the
assembly.
16
Properties of aggregation
 Transitivity : If A is part of B and B is part of C then A
is part of C.
 Antisymmetric : If A is part of B then B is not part of A.

17
Aggregation

Server DeskComputer
Aggregation

“whole”
“part” *
Client CPU Disk Drive Keyboard Mouse

18
Aggregation versus Association

 Aggregation is a special form of association, not an independent


concept.

 Aggregation adds semantic such as :


 If two objects are tightly bound by a part-whole relation it is

an aggregation.
 If the two objects are usually considered as independent, even

though they may often be linked, it is an association. ِ

19
Composition

 A composition is a strict form of aggregation, in which the parts


are existence-dependent on the entirely

 Composition is a part of aggregation with two additional


constraints.

1. A constituent part can belong to at most one assembly


2. Once a constituent part has been assigned an assembly, it has
equal lifetime with the assembly.

 This can be convenient for programming: Deletion of an


assembly object triggers deletion of all constituent objects via
composition.
20
Multiple Inheritance in UML

 So far we have seen single-inheritance: Each class had only one


direct super class. However, each class could have multiple
subclasses.
 But can a class also have multiple (direct) super classes? Yes, this
is called "multiple inheritance".

Aircraft PassengerVehicle

Boing747
21
Metadata
 Metadata is data that describes other data.
 Ex. A class definition is a metadata.
 Models are inherently metadata since they describe the
things being modeled.
 Many real world applications have metadata such as
catalogs, blueprints, dictionaries and directories.

22
Metadata

CarModel physicalCar
1 Describes *
modelName serialNumber
Year color
basePrice options

* *

1 manufacturer owner
1

Company Person

A car model (metadata relative to physical car) describes many


physical cars and holds common data.

23
Question-Answer session

Q 1 What is an association? Give examples


Q 2 Associations are usually bidirectional. Please describe.
Q 3 Describe the basic difference between aggregation and
inheritance. What do they have in common?
Q 4 What do you think “multiple inheritance” means?
Q 5 Which type of association is more likely to yield savings in the
amount of code required for implementation? why?
Q 6 Define the process of identifying objects, classes, inheritance,
associations & aggregation, attributes, and behaviors
Q 7 What do we mean by saying “Model/View/Controller”?

24
HomeWork

Q 1 What is an association? Give examples


Q 2 Associations are usually bidirectional. Please describe.
Q 3 Describe the basic difference between aggregation and
inheritance. What do they have in common?
Q 4 What do you think “multiple inheritance” means?
Q 5 Which type of association is more likely to yield savings in the
amount of code required for implementation? why?
Q 6 Define the process of identifying objects, classes, inheritance,
associations & aggregation, attributes, and behaviors
Q 7 What do we mean by saying “Model/View/Controller”?

25

You might also like