OOP Relationships and Associations, Lecture notes of Programming Paradigms

The different types of relationships and associations in Object-Oriented Programming (OOP). It defines association and multiplicity, and explains the different types of associations such as aggregation, composition, and dependency. The document also provides examples of methods used in OOP such as CompareTo, Contains, EndsWith, IndexOf, isEmpty, and lastIndexof. useful for students studying OOP and programming concepts.

Typology: Lecture notes

2020/2021

Available from 04/02/2022

gwen-hermo
gwen-hermo 🇵🇭

10 documents

1 / 9

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
OOP Mod 2
OOP Relationships
Relationships
Association two classes are connected in some way
Information about one class is linked to data about the other class
One class works with another to perform a task
One class acts upon the other class
o Multiplicity - the number of objects that can participate in an
association/relationship.
One class occupies one classroom (one-to-one)
One teacher teaches many classes (one-to-many)
One teacher teaches many students
One student learns from many teachers
(many-to-many)
TYPES OF ASSOCIATION
Aggregation - relationship between a whole and its parts. An instance of that
class can be a part of another class; shared object
<class_1> <association/verb> <class_2>
pf3
pf4
pf5
pf8
pf9

Partial preview of the text

Download OOP Relationships and Associations and more Lecture notes Programming Paradigms in PDF only on Docsity!

OOP Relationships

Relationships

  • Association two classes are connected in some way ➢ Information about one class is linked to data about the other class ➢ One class works with another to perform a task ➢ One class acts upon the other class o Multiplicity - the number of objects that can participate in an association/relationship. ➢ One class occupies one classroom (one-to-one) ➢ One teacher teaches many classes (one-to-many) ➢ One teacher teaches many students One student learns from many teachers (many-to-many) TYPES OF ASSOCIATION
  • Aggregation - relationship between a whole and its parts. An instance of that class can be a part of another class; shared object <class_1> <association/verb> <class_2>

o - symbol for a whole/larger object o An object can be part of one or more classes.

  • Composition - strong form of aggregation. In this kind of relationship, each part may belong to only one whole. o Symbol for an object that should belong to only one class
  • Dependency - relationship that shows that a class implementation requires another class for their specification/implementation. ❖ EXAMPLES

JAVA STRING

  • Array of parameters Length - as the total number of characters it contains. CharAt - returns the character at the specified index in a string; returns the character at the specified index in a string

CompareTo - compares two strings lexicographically Contains - used to check whether the specific set of characters are part of the given string or not ; returns a boolean

isEmpty - checks whether a string is empty or not; result in boolean lastIndexof - returns the position of the last occurrence of specified character(s) in a string

replace - replaces every occurrence of a given character with a new character and returns a new string split - used for splitting a String into its substrings based on the given delimiter or regular expression StartsWith - used for checking prefix of a String; returns a boolean Substring - a subset of another string. In case of substring startIndex is inclusive and endIndex is exclusive.