SlideShare a Scribd company logo
OO Relationships between
Classes
Sujit Kumar
Zenolocity LLC
Overview
•
•
•
•
•

Inheritance
Composition and Aggregation
Association
Using (Helper Classes)
Instantiation (Generics)
Inheritance
• Allows a class to reuse features &
functionalities of another class.
• Class it inherits from is also called Base Class
or Super Class or Parent class.
• The inheriting class is called Sub Class or
Derived Class or Child class.
• Sub Class can add more attributes & methods.
• Establishes an “IS-A” relationship from sub
class object to super class object.
Inheritance Hierarchies
• Examples of Inheritance Hierarchy:
Shape Hierarchy, Living Being Hierarchy.
• Specialization – go down the hierarchy.
• Generalization – go up the hierarchy.
Example: LivingBeing Class Hierarchy
Java Keywords related to Inheritance
• extends => inherits from
Example:
public class Plant extends LivingBeing {
…
…
}
• super(…) => invoke the base class constructor, must be
the first statement in the sub class constructor.
• super.someMethod() => scope resolution, helps to
invoke a method with the same name from the base
class.
Properties of Inheritance
• Every sub class object “is an” object of the
base class as well.
• Examples: Triangle is a Shape, Plant is a
LivingBeing
• Inheritance is NOT symmetric.
“A is a B” does not imply “B is-an A”.
• Inheritance is transitive.
If “A is a B” & “B is a C” => A “is a “ C.
Casting w.r.t Inherited Classes
• Example Class B inherits from Class A.
• A a = new B();
• The above is valid as every B is an A, upcasting
is implicit.
• B b = (B) a; // downcasting has to be
explicit, potential ClassCastException.
• B b = new A(); // Invalid as every B is not an A
Composition & Aggregation
• Indicates “has a” relationship between classes.
• Examples:
Car has an engine, LaptopBag has a Laptop.
• Aggregation => component can exist
independently of aggregate object. Example:
Laptop can exist independently of LaptopBag.
• Composition => component cannot exist
independently of composite object. Example:
Engine cannot exist independently of Car.
Association
• Classes that collaborate with each other within
the business domain.
• Can be uni-directional or bi-directional.
• Example: Customer and Teller at a Retail Bank.
The Teller serves many Customers. The Customer
can be serviced by many Tellers.
• Cardinality: 1-to-1, 1-to-Many, Many-to-Many.
• Many-to-Many may be broken into two 1-toMany relationships using a junction (link) class.
Using
• A class uses a helper class as a parameter to a
method or as a local variable of a method.
• Not same as association or aggregation.
• Example: In fluid dynamics, a method of a
class which calculates the flow in 2
dimensions can use a ComplexNumber class
as a parameter or local variable.
Instantiation (Generics)
• Not an object level relationship, but a class-toclass relationship.
• Share the definition of a class across different
data types.
• Example: A Queue can hold objects of type
HumanBeing or Animal or Integer. Behavior of
Queue (FIFO) is same irrespective of whether
it is holding Animals or HumanBeings or
Integers.
UML Notation for OO Relationships
• See the UML Notation Summary pdf file

More Related Content

PPT
Topic inheritance
Ankit Kumar
 
PPTX
Polymorphism
Nuha Noor
 
PPTX
Packages
Nuha Noor
 
PDF
Wdes105 day 3
Gene Babon
 
PPTX
Inheritance and Polymorphism
KartikKapgate
 
PPTX
Inheritance in java
HarshitaAshwani
 
PPTX
Java Chapter 04 - Writing Classes: part 1
DanWooster1
 
PDF
Java packages
Jeffrey Quevedo
 
Topic inheritance
Ankit Kumar
 
Polymorphism
Nuha Noor
 
Packages
Nuha Noor
 
Wdes105 day 3
Gene Babon
 
Inheritance and Polymorphism
KartikKapgate
 
Inheritance in java
HarshitaAshwani
 
Java Chapter 04 - Writing Classes: part 1
DanWooster1
 
Java packages
Jeffrey Quevedo
 

What's hot (20)

PDF
Inheritance
hccit
 
DOCX
Class notes(week 7) on packages
Kuntal Bhowmick
 
PPT
Java lec class, objects and constructors
Jan Niño Acierto
 
PPTX
OOPS Characteristics (With Examples in PHP)
baabtra.com - No. 1 supplier of quality freshers
 
PPTX
Introducing classes
Riaz Ahmed
 
PPT
Object Oriented Relationships
Taher Barodawala
 
PPTX
Java Chapter 04 - Writing Classes: part 2
DanWooster1
 
PPT
Learn Java language fundamentals with Unit nexus
Unit Nexus Pvt. Ltd.
 
PPTX
[OOP - Lec 04,05] Basic Building Blocks of OOP
Muhammad Hammad Waseem
 
PPT
150950107056 2150704
Prashant Mokani
 
PPTX
Is2215 lecture3 student (1)
dannygriff1
 
PPT
Data members and member functions
Harsh Patel
 
PPT
Lecture#01, object orientation
babak danyal
 
PDF
Take the Plunge with OOP from #pnwphp
Alena Holligan
 
DOCX
OOP Concepets and UML Class Diagrams
Bhathiya Nuwan
 
PPTX
[OOP - Lec 19] Static Member Functions
Muhammad Hammad Waseem
 
PPTX
Inheritance
Siddhesh Palkar
 
PPTX
Oops abap fundamental
biswajit2015
 
Inheritance
hccit
 
Class notes(week 7) on packages
Kuntal Bhowmick
 
Java lec class, objects and constructors
Jan Niño Acierto
 
OOPS Characteristics (With Examples in PHP)
baabtra.com - No. 1 supplier of quality freshers
 
Introducing classes
Riaz Ahmed
 
Object Oriented Relationships
Taher Barodawala
 
Java Chapter 04 - Writing Classes: part 2
DanWooster1
 
Learn Java language fundamentals with Unit nexus
Unit Nexus Pvt. Ltd.
 
[OOP - Lec 04,05] Basic Building Blocks of OOP
Muhammad Hammad Waseem
 
150950107056 2150704
Prashant Mokani
 
Is2215 lecture3 student (1)
dannygriff1
 
Data members and member functions
Harsh Patel
 
Lecture#01, object orientation
babak danyal
 
Take the Plunge with OOP from #pnwphp
Alena Holligan
 
OOP Concepets and UML Class Diagrams
Bhathiya Nuwan
 
[OOP - Lec 19] Static Member Functions
Muhammad Hammad Waseem
 
Inheritance
Siddhesh Palkar
 
Oops abap fundamental
biswajit2015
 
Ad

Viewers also liked (9)

PPTX
Java polymorphism
Sujit Kumar
 
PPTX
Java final keyword
Sujit Kumar
 
PPTX
Introduction to OOP with java
Sujit Kumar
 
PDF
Chapter1 Introduction to OOP (Java)
Dyah Fajar Nur Rohmah
 
PDF
Classes and Nested Classes in Java
Ravi_Kant_Sahu
 
PPS
Sw203 Lecture5 Class Acess Modifiers
Jargalsaikhan Alyeksandr
 
PDF
Chapter2 Encapsulation (Java)
Dyah Fajar Nur Rohmah
 
PDF
Java keywords
Ravi_Kant_Sahu
 
PPTX
Introduction to maven
Manos Georgopoulos
 
Java polymorphism
Sujit Kumar
 
Java final keyword
Sujit Kumar
 
Introduction to OOP with java
Sujit Kumar
 
Chapter1 Introduction to OOP (Java)
Dyah Fajar Nur Rohmah
 
Classes and Nested Classes in Java
Ravi_Kant_Sahu
 
Sw203 Lecture5 Class Acess Modifiers
Jargalsaikhan Alyeksandr
 
Chapter2 Encapsulation (Java)
Dyah Fajar Nur Rohmah
 
Java keywords
Ravi_Kant_Sahu
 
Introduction to maven
Manos Georgopoulos
 
Ad

Similar to OO relationships between classes (20)

PPTX
Inheritance.pptxci-Net.ci-Netci-Net.ci-Net..ci-Net.
kiran kumar
 
PPTX
Inheritance with examples.pptxInheritance with examples.pptxInheritance with ...
kiran kumar
 
PDF
Design pattern - part 1
Muhammad Yassein
 
PPTX
Relationships and their representation in a class diagram.pptx
nesarahmad37
 
PPTX
Std 12 computer chapter 6 object oriented concepts (part 2)
Nuzhat Memon
 
PPT
Lec 33 - inheritance
Princess Sam
 
PPT
Object and class relationships
Pooja mittal
 
PPTX
UML constructs
Dawood Faheem Abbasi
 
PPTX
FALLSEM2024-25_SWE2018_ETH_VL2024250103302_2024-10-04_Reference-Material-I.pptx
yadavdkshitij2003
 
PDF
Intro to UML
Marcin Szepczyński
 
PPT
8815346
Van Chau
 
PPT
Relations Class Diagram
halwal
 
PPT
M251_Meeting 5 (Inheritance and Polymorphism).ppt
smartashammari
 
PPT
Descriptions of class diagrams in software
ssuser9d62d6
 
PPT
06 class diagrams
Baskarkncet
 
PDF
Introduction to UML, a guide to learn.pdf
TARGARYEN001
 
PPTX
Relationship among classes
DheerendraMehar
 
PPT
Slide 5 Class Diagram
Niloy Rocker
 
PPTX
CLASS DIAGRAMS IN OBJECT ORIENTED ANALYSIS AND DESIGN
UmmuAhmed3
 
Inheritance.pptxci-Net.ci-Netci-Net.ci-Net..ci-Net.
kiran kumar
 
Inheritance with examples.pptxInheritance with examples.pptxInheritance with ...
kiran kumar
 
Design pattern - part 1
Muhammad Yassein
 
Relationships and their representation in a class diagram.pptx
nesarahmad37
 
Std 12 computer chapter 6 object oriented concepts (part 2)
Nuzhat Memon
 
Lec 33 - inheritance
Princess Sam
 
Object and class relationships
Pooja mittal
 
UML constructs
Dawood Faheem Abbasi
 
FALLSEM2024-25_SWE2018_ETH_VL2024250103302_2024-10-04_Reference-Material-I.pptx
yadavdkshitij2003
 
Intro to UML
Marcin Szepczyński
 
8815346
Van Chau
 
Relations Class Diagram
halwal
 
M251_Meeting 5 (Inheritance and Polymorphism).ppt
smartashammari
 
Descriptions of class diagrams in software
ssuser9d62d6
 
06 class diagrams
Baskarkncet
 
Introduction to UML, a guide to learn.pdf
TARGARYEN001
 
Relationship among classes
DheerendraMehar
 
Slide 5 Class Diagram
Niloy Rocker
 
CLASS DIAGRAMS IN OBJECT ORIENTED ANALYSIS AND DESIGN
UmmuAhmed3
 

More from Sujit Kumar (20)

PPTX
SFDC Database Basics
Sujit Kumar
 
PPTX
SFDC Database Security
Sujit Kumar
 
PPTX
SFDC Social Applications
Sujit Kumar
 
PPTX
SFDC Other Platform Features
Sujit Kumar
 
PPTX
SFDC Outbound Integrations
Sujit Kumar
 
PPTX
SFDC Inbound Integrations
Sujit Kumar
 
PPTX
SFDC UI - Advanced Visualforce
Sujit Kumar
 
PPTX
SFDC UI - Introduction to Visualforce
Sujit Kumar
 
PPTX
SFDC Deployments
Sujit Kumar
 
PPTX
SFDC Batch Apex
Sujit Kumar
 
PPTX
SFDC Data Loader
Sujit Kumar
 
PPTX
SFDC Advanced Apex
Sujit Kumar
 
PPTX
SFDC Introduction to Apex
Sujit Kumar
 
PPTX
SFDC Database Additional Features
Sujit Kumar
 
PPTX
Introduction to SalesForce
Sujit Kumar
 
PPTX
More about java strings - Immutability and String Pool
Sujit Kumar
 
PPTX
Hibernate First and Second level caches
Sujit Kumar
 
PPTX
Java equals hashCode Contract
Sujit Kumar
 
PPTX
Java Comparable and Comparator
Sujit Kumar
 
PPTX
Java build tools
Sujit Kumar
 
SFDC Database Basics
Sujit Kumar
 
SFDC Database Security
Sujit Kumar
 
SFDC Social Applications
Sujit Kumar
 
SFDC Other Platform Features
Sujit Kumar
 
SFDC Outbound Integrations
Sujit Kumar
 
SFDC Inbound Integrations
Sujit Kumar
 
SFDC UI - Advanced Visualforce
Sujit Kumar
 
SFDC UI - Introduction to Visualforce
Sujit Kumar
 
SFDC Deployments
Sujit Kumar
 
SFDC Batch Apex
Sujit Kumar
 
SFDC Data Loader
Sujit Kumar
 
SFDC Advanced Apex
Sujit Kumar
 
SFDC Introduction to Apex
Sujit Kumar
 
SFDC Database Additional Features
Sujit Kumar
 
Introduction to SalesForce
Sujit Kumar
 
More about java strings - Immutability and String Pool
Sujit Kumar
 
Hibernate First and Second level caches
Sujit Kumar
 
Java equals hashCode Contract
Sujit Kumar
 
Java Comparable and Comparator
Sujit Kumar
 
Java build tools
Sujit Kumar
 

Recently uploaded (20)

PDF
SparkLabs Primer on Artificial Intelligence 2025
SparkLabs Group
 
PDF
Automating ArcGIS Content Discovery with FME: A Real World Use Case
Safe Software
 
PDF
Data_Analytics_vs_Data_Science_vs_BI_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
 
PDF
Peak of Data & AI Encore - Real-Time Insights & Scalable Editing with ArcGIS
Safe Software
 
PDF
Orbitly Pitch Deck|A Mission-Driven Platform for Side Project Collaboration (...
zz41354899
 
PDF
Using Anchore and DefectDojo to Stand Up Your DevSecOps Function
Anchore
 
PPTX
cloud computing vai.pptx for the project
vaibhavdobariyal79
 
PPTX
Dev Dives: Automate, test, and deploy in one place—with Unified Developer Exp...
AndreeaTom
 
PDF
The Future of Artificial Intelligence (AI)
Mukul
 
PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
PPTX
AI and Robotics for Human Well-being.pptx
JAYMIN SUTHAR
 
PDF
Doc9.....................................
SofiaCollazos
 
PPTX
What-is-the-World-Wide-Web -- Introduction
tonifi9488
 
PDF
Oracle AI Vector Search- Getting Started and what's new in 2025- AIOUG Yatra ...
Sandesh Rao
 
PDF
How ETL Control Logic Keeps Your Pipelines Safe and Reliable.pdf
Stryv Solutions Pvt. Ltd.
 
PDF
CIFDAQ's Market Wrap : Bears Back in Control?
CIFDAQ
 
PDF
Economic Impact of Data Centres to the Malaysian Economy
flintglobalapac
 
PDF
The Future of Mobile Is Context-Aware—Are You Ready?
iProgrammer Solutions Private Limited
 
PDF
OFFOFFBOX™ – A New Era for African Film | Startup Presentation
ambaicciwalkerbrian
 
PPTX
Introduction to Flutter by Ayush Desai.pptx
ayushdesai204
 
SparkLabs Primer on Artificial Intelligence 2025
SparkLabs Group
 
Automating ArcGIS Content Discovery with FME: A Real World Use Case
Safe Software
 
Data_Analytics_vs_Data_Science_vs_BI_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
 
Peak of Data & AI Encore - Real-Time Insights & Scalable Editing with ArcGIS
Safe Software
 
Orbitly Pitch Deck|A Mission-Driven Platform for Side Project Collaboration (...
zz41354899
 
Using Anchore and DefectDojo to Stand Up Your DevSecOps Function
Anchore
 
cloud computing vai.pptx for the project
vaibhavdobariyal79
 
Dev Dives: Automate, test, and deploy in one place—with Unified Developer Exp...
AndreeaTom
 
The Future of Artificial Intelligence (AI)
Mukul
 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
AI and Robotics for Human Well-being.pptx
JAYMIN SUTHAR
 
Doc9.....................................
SofiaCollazos
 
What-is-the-World-Wide-Web -- Introduction
tonifi9488
 
Oracle AI Vector Search- Getting Started and what's new in 2025- AIOUG Yatra ...
Sandesh Rao
 
How ETL Control Logic Keeps Your Pipelines Safe and Reliable.pdf
Stryv Solutions Pvt. Ltd.
 
CIFDAQ's Market Wrap : Bears Back in Control?
CIFDAQ
 
Economic Impact of Data Centres to the Malaysian Economy
flintglobalapac
 
The Future of Mobile Is Context-Aware—Are You Ready?
iProgrammer Solutions Private Limited
 
OFFOFFBOX™ – A New Era for African Film | Startup Presentation
ambaicciwalkerbrian
 
Introduction to Flutter by Ayush Desai.pptx
ayushdesai204
 

OO relationships between classes

  • 3. Inheritance • Allows a class to reuse features & functionalities of another class. • Class it inherits from is also called Base Class or Super Class or Parent class. • The inheriting class is called Sub Class or Derived Class or Child class. • Sub Class can add more attributes & methods. • Establishes an “IS-A” relationship from sub class object to super class object.
  • 4. Inheritance Hierarchies • Examples of Inheritance Hierarchy: Shape Hierarchy, Living Being Hierarchy. • Specialization – go down the hierarchy. • Generalization – go up the hierarchy.
  • 6. Java Keywords related to Inheritance • extends => inherits from Example: public class Plant extends LivingBeing { … … } • super(…) => invoke the base class constructor, must be the first statement in the sub class constructor. • super.someMethod() => scope resolution, helps to invoke a method with the same name from the base class.
  • 7. Properties of Inheritance • Every sub class object “is an” object of the base class as well. • Examples: Triangle is a Shape, Plant is a LivingBeing • Inheritance is NOT symmetric. “A is a B” does not imply “B is-an A”. • Inheritance is transitive. If “A is a B” & “B is a C” => A “is a “ C.
  • 8. Casting w.r.t Inherited Classes • Example Class B inherits from Class A. • A a = new B(); • The above is valid as every B is an A, upcasting is implicit. • B b = (B) a; // downcasting has to be explicit, potential ClassCastException. • B b = new A(); // Invalid as every B is not an A
  • 9. Composition & Aggregation • Indicates “has a” relationship between classes. • Examples: Car has an engine, LaptopBag has a Laptop. • Aggregation => component can exist independently of aggregate object. Example: Laptop can exist independently of LaptopBag. • Composition => component cannot exist independently of composite object. Example: Engine cannot exist independently of Car.
  • 10. Association • Classes that collaborate with each other within the business domain. • Can be uni-directional or bi-directional. • Example: Customer and Teller at a Retail Bank. The Teller serves many Customers. The Customer can be serviced by many Tellers. • Cardinality: 1-to-1, 1-to-Many, Many-to-Many. • Many-to-Many may be broken into two 1-toMany relationships using a junction (link) class.
  • 11. Using • A class uses a helper class as a parameter to a method or as a local variable of a method. • Not same as association or aggregation. • Example: In fluid dynamics, a method of a class which calculates the flow in 2 dimensions can use a ComplexNumber class as a parameter or local variable.
  • 12. Instantiation (Generics) • Not an object level relationship, but a class-toclass relationship. • Share the definition of a class across different data types. • Example: A Queue can hold objects of type HumanBeing or Animal or Integer. Behavior of Queue (FIFO) is same irrespective of whether it is holding Animals or HumanBeings or Integers.
  • 13. UML Notation for OO Relationships • See the UML Notation Summary pdf file