Understanding Associations and Relationships between Objects in Computer Science, Slides of Object Oriented Programming

An overview of associations between classes, their conceptual and implementation meanings, and uml representation. It covers various types of associations, multiplicity, and implementation considerations. Examples include 'student' and 'university', 'examiner' and 'paper', and 'course' and 'module'.

Typology: Slides

2011/2012

Uploaded on 07/17/2012

banani
banani 🇮🇳

4.3

(3)

91 documents

1 / 8

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Relationships between Objects
Associations
Lecture 7
2
Overview
nAssociation
nDependency
nAggregation
nComposition
nImplementation of Relationships
3
Associations between classes
nA system consists of coordinating objects
nInheritance describes the hierarchical
relationship between classes/ objects
nAssociation between classes describes the
role the objects of these classes play in the
system
nFor example: Lecturer teaches Student;
If Lecturer and Student are classes then
teaches is an association between them
docsity.com
pf3
pf4
pf5
pf8

Partial preview of the text

Download Understanding Associations and Relationships between Objects in Computer Science and more Slides Object Oriented Programming in PDF only on Docsity!

Relationships between Objects

Associations

Lecture 7

2

Overview

n Association

n Dependency

n Aggregation

n Composition

n Implementation of Relationships

3

Associations between classes

n A system consists of coordinating objects n Inheritance describes the hierarchical relationship between classes/ objects n Association between classes describes the role the objects of these classes play in the system n For example: Lecturer teaches Student; If Lecturer and Student are classes then teaches is an association between them

4

More Examples…

n BookBorrower borrows Copy of Book n Copy is copy of Book n Author writes Book n Student takes Module n Semester has Module

n Pattern: ClassName associationName ClassName

5

Understanding Associations

n Conceptually

n Implementation point of view

6

Conceptual Meaning

n Two classes are associated if the object

of one class sends a message to (uses)

the object of the other class

10

Implementation of Point 3

n An instance of class A has one or more

attributes whose values are instances

of class B

class A { B b; // declare ‘b’ void somethingACanDo() { b = anotherInstanceOfClassB; } }

11

Implementation of Point 4

n An instance of class A receives a

message with an instance of class B as

an argument

class A { ... void somethingACanDo(B b) { b.doSomething(); } }

12

… knows about …

In all the previous cases:

class A knows about class B

n Indicates direction of message (i.e., A

sends message to B)

13

UML Representation of

Association

n Name of association and direction of message

n Associations with roles

University^ τ^ studies in Student

University^ paysυ Lecturer

University Person

student

employer teacher

14

Cardinality – Multiplicity of

Association

n Multiplicity information specifies the number of instances that participate in a relationship

n Example: n A particular university has several students n A given student belongs to a single university

University^ |^ studies in Student

1 *

15

More Examples

Examiner^ examines Paper

1 *

WorkDay^ has Shift

1 4

Worker^ works Shift

10..20 1..

19

UML Notation : Dependency

Person

House buys

Semester Date

starts on

20

UML Notation : Aggregation

1..* 5..* Course Module

1..* 1..* EmployeeList Employee

21

UML Notation : Composition

1 0..* Window Button

1 9 TicTacToeGame Square

In compositions, the whole has a multiplicity of zero or 0..1; that is.. A part cannot be part of more than one whole

22

Aggregation vs. Composition

n In C++ we can refer to objects either

by value or by reference

n It is aggregation if the whole contains a

reference or pointer to the part

n It is composition if the whole contains

the part by value

23

Summary

n Association between classes

n Links between objects

n Types of Associations

n UML Notations

n Multiplicity of associations

n Implementation considerations