SlideShare a Scribd company logo
3
Most read
4
Most read
6
Most read
Object Oriented
Concept
Part 2
Aggregation & Composition
Aggregation vs. Composition
Inheritance
Composition vs. Inheritance Presented by Nuzhat Ibrahim Memon
Presented by Nuzhat Ibrahim Memon
2
Name
• first name: String
• last name: string
• display()
Person
• nm: Name
• addr:Address
• birthdate:date
• setbirthdate(d:int, m:int,
y:int):date
Address
•house: string
•street:string
•state:string
•pincode:int
•fulladress(): string
Teacher
• Subject : string
• lecture(d:date, t:time)
• When objects of one class are composed of objects of
other class, it is called aggregation or composition.
• It represents “has-a” or “a-part-of” relationship
between classes.
Presented by Nuzhat Ibrahim Memon
3
Person
• nm: Name
• addr: Address
• birthdate:date
• setbirthdate(d:int, m:int,
y:int):date
• display()
Name
• First Name: string
• Middle name:string
• last name:string
• fullName():string
• display()
Address
• house: string
• street:string
• state:string
• pincode:int
• fulladress(): string
• display()
Screen
• length: int
• width: int
• model: string
Motherboard
• model: string
• company: string
computer
• scr: Screen
• mb: Motherboard
• Take an example of ‘person’ class
• We will define two classed ‘Name’ and ‘Address’.
• Class ‘Name’ has an attribute first name, middle
name and last name.
• Class ‘address’ has an attribute house, street, city,
state and pincode.
• The data type of attributes ‘nm’ and ‘addr’ is class
‘Name’ and ‘Address’ respectively.
• Thus class ‘person’ contains object of class ‘Name’
and ‘Address’
• Aggregation represents non-exclusive relationship between two
classes.
• In aggregation, the class that forms part of the owner class can exist
independently.
• The life of an object of the part class is not determined by the owner
class.
• Object Address may be shared by more than one person. Address is
not exclusive to any one person. So, when a person is deleted, the
corresponding address cannot be deleted.
• Basic aggregation is represented using an empty diamond symbol
next to the whole class.
• Composition represents exclusive relationship between two classes.
• Composition is a strong type of aggregation where the lifetime of the
class depends on the existence of the owner class.
• If an object of aggregating class is deleted, its part class object also
will get deleted. For eg. When an object of class person is deleted, the
object of class name is also deleted. Name is associated exclusively
with single person.
• Composition relationships are represented using a filled diamond
next to the whole class.
Owner class,
Whole class or
aggregating class
Presented by Nuzhat Ibrahim Memon
4
Name
• first name: string
• Middle name: string
• last name: string
• display()
Person
• nm: Name
• addr:Address
• birthdate:date
• setbirthdate(d:int,
m:int, y:int):date
Address
•house: string
•street:string
•state:string
•pincode:int
•fulladress(): string
Subject class,
part class or
aggregated class
Subject class,
part class or
aggregated class
Composition Relationship
(Filled diamond)
Aggregation Relationship
(Empty diamond)
• Inheritance is generally referred to as ‘is-a-kind-of’ relationship
between two classes.
• Inheritance is appropriate when one class is ‘a kind of’ other
class. For e.g. teacher is a kind of person. So, all the attributes
and methods of class ‘Person’ are applicable to class ‘Teacher’
also.
• Inheritance refers to the capability of defining a new class of
objects that inherits the characteristic of another existing class.
• In other words, class ‘Teacher’ inherits all attributes and
behavior of class ‘Person’. Class ‘Teacher’ may have additional
attributes like subject and method like taking lectures of the
subject. In such scenario, class ‘Teacher’ can be defined using
class ‘Person’.
• The feature provides reusability where existing methods can be
reused without redefining. In other words, the data attributes
and methods of the super class are available to objects in the
sub class without rewriting their declarations.
Presented by Nuzhat Ibrahim Memon
5
Person
• name:string
• city: string
• gender:char=‘F’
• setBirthdate(d:int, m:int, y:int):date
• display()
Teacher
• subject: string
• lecture (d:date, t:time)
Existing class is called New Class is called
super class sub class
parent class child class
base class derived class
In Class Diagram, Inheritance is represented using
an arrow pointing to super class.
Presented by Nuzhat Ibrahim Memon
6
• Generalization is another name for inheritance or “is a” relationship.
• It refers to a relationship between two classes where one class is a specialized
version of another.
• Common attributes and methods are defined in super class.
• Sub class is a specialized version with additional attributes and methods.
• There may be a classical hierarchy of inheritance between classes. For e.g. class
‘Employee’ can be derived from class ‘Person’, then class ‘Teacher’ can be derived
from ‘Employee’. Here employee is a kind of person and teacher is a kind of
employee. Such type of inheritance is known as multilevel inheritance.
• A class can also be derived using more than parent classes. For e.g. a child inherits
the characteristics of both mother and father. When a class is derived from two or
more classes. It is known as multiple inheritance. In multiple inheritance, child will
get properties from father as well as mother from both the parents.
• Example: airplane is a kind of vehicle as well as flying object.
Person
Teacher
Employee
Child
Father Mother
Airplane
Vehicle
Flying
object
Person
(Super Class)
Teacher
(Sub Class)
Common attributes & methods
Additional attributes & methods
Grandfather
Son
Father
• In inheritance, class inherits from other classes
in order to share, reuse or extend functionality.
Here there exists ‘is a’ or ‘a kind of’ relationship
between super class and sub class.
• In composition, classes do not inherit from other
classes, but are ‘composed of’ other classes.
Class contains the attributes where some
attributes are of objects of other class types.
Presented by Nuzhat Ibrahim Memon
7
Social
Networking Site
Facebook Users
is a
has a
Nuzhat Memon
website:
nuzhatmemon.com
Email:
nuzhat.memon@gmail.com
Ad

Recommended

Std 12 computer chapter 6 object oriented concepts (part 1)
Std 12 computer chapter 6 object oriented concepts (part 1)
Nuzhat Memon
 
Unit I - Evaluation of expression
Unit I - Evaluation of expression
DrkhanchanaR
 
Regular expressions in Python
Regular expressions in Python
Sujith Kumar
 
Std 12 computer chapter 8 classes and object in java (part 2)
Std 12 computer chapter 8 classes and object in java (part 2)
Nuzhat Memon
 
Object Oriented Programming Concepts for beginners
Object Oriented Programming Concepts for beginners
Vibhawa Nirmal
 
Arrays in Java
Arrays in Java
Abhilash Nair
 
Java interfaces
Java interfaces
Raja Sekhar
 
Searching and sorting
Searching and sorting
PoojithaBollikonda
 
Arrays
Arrays
archikabhatia
 
Java access modifiers
Java access modifiers
Srinivas Reddy
 
Introduction to Array ppt
Introduction to Array ppt
sandhya yadav
 
Data structures
Data structures
Sneha Chopra
 
Stack application
Stack application
Student
 
Introduction to method overloading & method overriding in java hdm
Introduction to method overloading & method overriding in java hdm
Harshal Misalkar
 
Constants in java
Constants in java
Manojkumar C
 
Python : Regular expressions
Python : Regular expressions
Emertxe Information Technologies Pvt Ltd
 
Stack Data Structure
Stack Data Structure
Rabin BK
 
Data Structures (CS8391)
Data Structures (CS8391)
Elavarasi K
 
Arrays in java
Arrays in java
TharuniDiddekunta
 
Doubly Linked List
Doubly Linked List
Ninad Mankar
 
Polymorphism presentation in java
Polymorphism presentation in java
Ahsan Raja
 
Access specifier
Access specifier
zindadili
 
Wrapper class
Wrapper class
kamal kotecha
 
Stacks and Queue - Data Structures
Stacks and Queue - Data Structures
Dr. Jasmine Beulah Gnanadurai
 
Interface in java
Interface in java
PhD Research Scholar
 
Polymorphism in C++
Polymorphism in C++
Rabin BK
 
Polymorphism in java
Polymorphism in java
Elizabeth alexander
 
Command line arguments.21
Command line arguments.21
myrajendra
 
UML constructs
UML constructs
Dawood Faheem Abbasi
 
Object Oriented Principles
Object Oriented Principles
Emprovise
 

More Related Content

What's hot (20)

Arrays
Arrays
archikabhatia
 
Java access modifiers
Java access modifiers
Srinivas Reddy
 
Introduction to Array ppt
Introduction to Array ppt
sandhya yadav
 
Data structures
Data structures
Sneha Chopra
 
Stack application
Stack application
Student
 
Introduction to method overloading & method overriding in java hdm
Introduction to method overloading & method overriding in java hdm
Harshal Misalkar
 
Constants in java
Constants in java
Manojkumar C
 
Python : Regular expressions
Python : Regular expressions
Emertxe Information Technologies Pvt Ltd
 
Stack Data Structure
Stack Data Structure
Rabin BK
 
Data Structures (CS8391)
Data Structures (CS8391)
Elavarasi K
 
Arrays in java
Arrays in java
TharuniDiddekunta
 
Doubly Linked List
Doubly Linked List
Ninad Mankar
 
Polymorphism presentation in java
Polymorphism presentation in java
Ahsan Raja
 
Access specifier
Access specifier
zindadili
 
Wrapper class
Wrapper class
kamal kotecha
 
Stacks and Queue - Data Structures
Stacks and Queue - Data Structures
Dr. Jasmine Beulah Gnanadurai
 
Interface in java
Interface in java
PhD Research Scholar
 
Polymorphism in C++
Polymorphism in C++
Rabin BK
 
Polymorphism in java
Polymorphism in java
Elizabeth alexander
 
Command line arguments.21
Command line arguments.21
myrajendra
 

Similar to Std 12 computer chapter 6 object oriented concepts (part 2) (20)

UML constructs
UML constructs
Dawood Faheem Abbasi
 
Object Oriented Principles
Object Oriented Principles
Emprovise
 
Intro To C++ - Class #23: Inheritance, Part 2
Intro To C++ - Class #23: Inheritance, Part 2
Blue Elephant Consulting
 
Relationships and their representation in a class diagram.pptx
Relationships and their representation in a class diagram.pptx
nesarahmad37
 
Lec 33 - inheritance
Lec 33 - inheritance
Princess Sam
 
8815346
8815346
Van Chau
 
OOP Presentation.pptx
OOP Presentation.pptx
DurgaPrasadVasantati
 
OOP Presentation.pptx
OOP Presentation.pptx
DurgaPrasadVasantati
 
Object Oriented Relationships
Object Oriented Relationships
Taher Barodawala
 
FALLSEM2024-25_SWE2018_ETH_VL2024250103302_2024-10-04_Reference-Material-I.pptx
FALLSEM2024-25_SWE2018_ETH_VL2024250103302_2024-10-04_Reference-Material-I.pptx
yadavdkshitij2003
 
What is OOP?
What is OOP?
Amin Uddin
 
Class Diagram Object Oriented Programming
Class Diagram Object Oriented Programming
gedeios
 
Class diagrams
Class diagrams
Vince Carter
 
Lecture#01, object orientation
Lecture#01, object orientation
babak danyal
 
class Diagram.ppt
class Diagram.ppt
usama537223
 
python.pptx
python.pptx
Mvidhya9
 
CHAP1 - OBJECT ORIENTED PROGRAMMING.pptx
CHAP1 - OBJECT ORIENTED PROGRAMMING.pptx
0wenraiwenbal01
 
ملخص تحليل الانظمة وتصميمها - الوحدة الخامسة
ملخص تحليل الانظمة وتصميمها - الوحدة الخامسة
جامعة القدس المفتوحة
 
Slide 5 Class Diagram
Slide 5 Class Diagram
Niloy Rocker
 
introofUML.pptx
introofUML.pptx
RojaPogul1
 
Object Oriented Principles
Object Oriented Principles
Emprovise
 
Intro To C++ - Class #23: Inheritance, Part 2
Intro To C++ - Class #23: Inheritance, Part 2
Blue Elephant Consulting
 
Relationships and their representation in a class diagram.pptx
Relationships and their representation in a class diagram.pptx
nesarahmad37
 
Lec 33 - inheritance
Lec 33 - inheritance
Princess Sam
 
Object Oriented Relationships
Object Oriented Relationships
Taher Barodawala
 
FALLSEM2024-25_SWE2018_ETH_VL2024250103302_2024-10-04_Reference-Material-I.pptx
FALLSEM2024-25_SWE2018_ETH_VL2024250103302_2024-10-04_Reference-Material-I.pptx
yadavdkshitij2003
 
Class Diagram Object Oriented Programming
Class Diagram Object Oriented Programming
gedeios
 
Lecture#01, object orientation
Lecture#01, object orientation
babak danyal
 
class Diagram.ppt
class Diagram.ppt
usama537223
 
python.pptx
python.pptx
Mvidhya9
 
CHAP1 - OBJECT ORIENTED PROGRAMMING.pptx
CHAP1 - OBJECT ORIENTED PROGRAMMING.pptx
0wenraiwenbal01
 
ملخص تحليل الانظمة وتصميمها - الوحدة الخامسة
ملخص تحليل الانظمة وتصميمها - الوحدة الخامسة
جامعة القدس المفتوحة
 
Slide 5 Class Diagram
Slide 5 Class Diagram
Niloy Rocker
 
introofUML.pptx
introofUML.pptx
RojaPogul1
 
Ad

More from Nuzhat Memon (20)

Std 10 chapter 11 data type, expression and operators important MCQs
Std 10 chapter 11 data type, expression and operators important MCQs
Nuzhat Memon
 
Std 10 Chapter 10 Introduction to C Language Important MCQs
Std 10 Chapter 10 Introduction to C Language Important MCQs
Nuzhat Memon
 
Std 12 chapter 7 Java Basics Important MCQs
Std 12 chapter 7 Java Basics Important MCQs
Nuzhat Memon
 
Std 12 computer chapter 8 classes and objects in java important MCQs
Std 12 computer chapter 8 classes and objects in java important MCQs
Nuzhat Memon
 
Std 12 Computer Chapter 6 object oriented concept important mcqs
Std 12 Computer Chapter 6 object oriented concept important mcqs
Nuzhat Memon
 
Std 12 computer java basics part 3 control structure
Std 12 computer java basics part 3 control structure
Nuzhat Memon
 
Std 12 Computer Chapter 7 Java Basics (Part 2)
Std 12 Computer Chapter 7 Java Basics (Part 2)
Nuzhat Memon
 
Std 12 Computer Chapter 7 Java Basics (Part 1)
Std 12 Computer Chapter 7 Java Basics (Part 1)
Nuzhat Memon
 
Std 12 Computer Chapter 13 other useful free tools and services important MCQs
Std 12 Computer Chapter 13 other useful free tools and services important MCQs
Nuzhat Memon
 
Std 12 Computer Chapter 9 Working with Array and String in Java important MCQs
Std 12 Computer Chapter 9 Working with Array and String in Java important MCQs
Nuzhat Memon
 
Std 10 computer chapter 10 introduction to c language (part2)
Std 10 computer chapter 10 introduction to c language (part2)
Nuzhat Memon
 
Std 10 computer chapter 10 introduction to c language (part1)
Std 10 computer chapter 10 introduction to c language (part1)
Nuzhat Memon
 
Std 10 computer chapter 9 Problems and Problem Solving
Std 10 computer chapter 9 Problems and Problem Solving
Nuzhat Memon
 
Std 11 Computer Chapter 5 Using Pictures in Synfig (Practical 3: Masking to R...
Std 11 Computer Chapter 5 Using Pictures in Synfig (Practical 3: Masking to R...
Nuzhat Memon
 
Chapter 5 Using Pictures in Synfig (Practical 2: Masking to hide area in synfig)
Chapter 5 Using Pictures in Synfig (Practical 2: Masking to hide area in synfig)
Nuzhat Memon
 
Std 11 Computer Chapter 5 Using Pictures in Synfig (Practical 1 Basics Opera...
Std 11 Computer Chapter 5 Using Pictures in Synfig (Practical 1 Basics Opera...
Nuzhat Memon
 
Std 11 Computer Chapter 4 Introduction to Layers (Part 3 Solving Textual Exe...
Std 11 Computer Chapter 4 Introduction to Layers (Part 3 Solving Textual Exe...
Nuzhat Memon
 
Std 11 Computer Chapter 4 Introduction to Layers (Part 2 Practical :Rotation ...
Std 11 Computer Chapter 4 Introduction to Layers (Part 2 Practical :Rotation ...
Nuzhat Memon
 
Std 11 Computer Chapter 4 Introduction to Layers
Std 11 Computer Chapter 4 Introduction to Layers
Nuzhat Memon
 
Std 11 Computer Chapter 3 Creating Animation using Synfig (Part 3) [practica...
Std 11 Computer Chapter 3 Creating Animation using Synfig (Part 3) [practica...
Nuzhat Memon
 
Std 10 chapter 11 data type, expression and operators important MCQs
Std 10 chapter 11 data type, expression and operators important MCQs
Nuzhat Memon
 
Std 10 Chapter 10 Introduction to C Language Important MCQs
Std 10 Chapter 10 Introduction to C Language Important MCQs
Nuzhat Memon
 
Std 12 chapter 7 Java Basics Important MCQs
Std 12 chapter 7 Java Basics Important MCQs
Nuzhat Memon
 
Std 12 computer chapter 8 classes and objects in java important MCQs
Std 12 computer chapter 8 classes and objects in java important MCQs
Nuzhat Memon
 
Std 12 Computer Chapter 6 object oriented concept important mcqs
Std 12 Computer Chapter 6 object oriented concept important mcqs
Nuzhat Memon
 
Std 12 computer java basics part 3 control structure
Std 12 computer java basics part 3 control structure
Nuzhat Memon
 
Std 12 Computer Chapter 7 Java Basics (Part 2)
Std 12 Computer Chapter 7 Java Basics (Part 2)
Nuzhat Memon
 
Std 12 Computer Chapter 7 Java Basics (Part 1)
Std 12 Computer Chapter 7 Java Basics (Part 1)
Nuzhat Memon
 
Std 12 Computer Chapter 13 other useful free tools and services important MCQs
Std 12 Computer Chapter 13 other useful free tools and services important MCQs
Nuzhat Memon
 
Std 12 Computer Chapter 9 Working with Array and String in Java important MCQs
Std 12 Computer Chapter 9 Working with Array and String in Java important MCQs
Nuzhat Memon
 
Std 10 computer chapter 10 introduction to c language (part2)
Std 10 computer chapter 10 introduction to c language (part2)
Nuzhat Memon
 
Std 10 computer chapter 10 introduction to c language (part1)
Std 10 computer chapter 10 introduction to c language (part1)
Nuzhat Memon
 
Std 10 computer chapter 9 Problems and Problem Solving
Std 10 computer chapter 9 Problems and Problem Solving
Nuzhat Memon
 
Std 11 Computer Chapter 5 Using Pictures in Synfig (Practical 3: Masking to R...
Std 11 Computer Chapter 5 Using Pictures in Synfig (Practical 3: Masking to R...
Nuzhat Memon
 
Chapter 5 Using Pictures in Synfig (Practical 2: Masking to hide area in synfig)
Chapter 5 Using Pictures in Synfig (Practical 2: Masking to hide area in synfig)
Nuzhat Memon
 
Std 11 Computer Chapter 5 Using Pictures in Synfig (Practical 1 Basics Opera...
Std 11 Computer Chapter 5 Using Pictures in Synfig (Practical 1 Basics Opera...
Nuzhat Memon
 
Std 11 Computer Chapter 4 Introduction to Layers (Part 3 Solving Textual Exe...
Std 11 Computer Chapter 4 Introduction to Layers (Part 3 Solving Textual Exe...
Nuzhat Memon
 
Std 11 Computer Chapter 4 Introduction to Layers (Part 2 Practical :Rotation ...
Std 11 Computer Chapter 4 Introduction to Layers (Part 2 Practical :Rotation ...
Nuzhat Memon
 
Std 11 Computer Chapter 4 Introduction to Layers
Std 11 Computer Chapter 4 Introduction to Layers
Nuzhat Memon
 
Std 11 Computer Chapter 3 Creating Animation using Synfig (Part 3) [practica...
Std 11 Computer Chapter 3 Creating Animation using Synfig (Part 3) [practica...
Nuzhat Memon
 
Ad

Recently uploaded (20)

Paper 107 | From Watchdog to Lapdog: Ishiguro’s Fiction and the Rise of “Godi...
Paper 107 | From Watchdog to Lapdog: Ishiguro’s Fiction and the Rise of “Godi...
Rajdeep Bavaliya
 
Peer Teaching Observations During School Internship
Peer Teaching Observations During School Internship
AjayaMohanty7
 
VCE Literature Section A Exam Response Guide
VCE Literature Section A Exam Response Guide
jpinnuck
 
ENGLISH-5 Q1 Lesson 1.pptx - Story Elements
ENGLISH-5 Q1 Lesson 1.pptx - Story Elements
Mayvel Nadal
 
English 3 Quarter 1_LEwithLAS_Week 1.pdf
English 3 Quarter 1_LEwithLAS_Week 1.pdf
DeAsisAlyanajaneH
 
GREAT QUIZ EXCHANGE 2025 - GENERAL QUIZ.pptx
GREAT QUIZ EXCHANGE 2025 - GENERAL QUIZ.pptx
Ronisha Das
 
Values Education 10 Quarter 1 Module .pptx
Values Education 10 Quarter 1 Module .pptx
JBPafin
 
Great Governors' Send-Off Quiz 2025 Prelims IIT KGP
Great Governors' Send-Off Quiz 2025 Prelims IIT KGP
IIT Kharagpur Quiz Club
 
This is why students from these 44 institutions have not received National Se...
This is why students from these 44 institutions have not received National Se...
Kweku Zurek
 
Vitamin and Nutritional Deficiencies.pptx
Vitamin and Nutritional Deficiencies.pptx
Vishal Chanalia
 
THE PSYCHOANALYTIC OF THE BLACK CAT BY EDGAR ALLAN POE (1).pdf
THE PSYCHOANALYTIC OF THE BLACK CAT BY EDGAR ALLAN POE (1).pdf
nabilahk908
 
How payment terms are configured in Odoo 18
How payment terms are configured in Odoo 18
Celine George
 
How to Manage Different Customer Addresses in Odoo 18 Accounting
How to Manage Different Customer Addresses in Odoo 18 Accounting
Celine George
 
University of Ghana Cracks Down on Misconduct: Over 100 Students Sanctioned
University of Ghana Cracks Down on Misconduct: Over 100 Students Sanctioned
Kweku Zurek
 
LDMMIA Yoga S10 Free Workshop Grad Level
LDMMIA Yoga S10 Free Workshop Grad Level
LDM & Mia eStudios
 
ENGLISH_Q1_W1 PowerPoint grade 3 quarter 1 week 1
ENGLISH_Q1_W1 PowerPoint grade 3 quarter 1 week 1
jutaydeonne
 
IIT KGP Quiz Week 2024 Sports Quiz (Prelims + Finals)
IIT KGP Quiz Week 2024 Sports Quiz (Prelims + Finals)
IIT Kharagpur Quiz Club
 
Public Health For The 21st Century 1st Edition Judy Orme Jane Powell
Public Health For The 21st Century 1st Edition Judy Orme Jane Powell
trjnesjnqg7801
 
Filipino 9 Maikling Kwento Ang Ama Panitikang Asiyano
Filipino 9 Maikling Kwento Ang Ama Panitikang Asiyano
sumadsadjelly121997
 
NSUMD_M1 Library Orientation_June 11, 2025.pptx
NSUMD_M1 Library Orientation_June 11, 2025.pptx
Julie Sarpy
 
Paper 107 | From Watchdog to Lapdog: Ishiguro’s Fiction and the Rise of “Godi...
Paper 107 | From Watchdog to Lapdog: Ishiguro’s Fiction and the Rise of “Godi...
Rajdeep Bavaliya
 
Peer Teaching Observations During School Internship
Peer Teaching Observations During School Internship
AjayaMohanty7
 
VCE Literature Section A Exam Response Guide
VCE Literature Section A Exam Response Guide
jpinnuck
 
ENGLISH-5 Q1 Lesson 1.pptx - Story Elements
ENGLISH-5 Q1 Lesson 1.pptx - Story Elements
Mayvel Nadal
 
English 3 Quarter 1_LEwithLAS_Week 1.pdf
English 3 Quarter 1_LEwithLAS_Week 1.pdf
DeAsisAlyanajaneH
 
GREAT QUIZ EXCHANGE 2025 - GENERAL QUIZ.pptx
GREAT QUIZ EXCHANGE 2025 - GENERAL QUIZ.pptx
Ronisha Das
 
Values Education 10 Quarter 1 Module .pptx
Values Education 10 Quarter 1 Module .pptx
JBPafin
 
Great Governors' Send-Off Quiz 2025 Prelims IIT KGP
Great Governors' Send-Off Quiz 2025 Prelims IIT KGP
IIT Kharagpur Quiz Club
 
This is why students from these 44 institutions have not received National Se...
This is why students from these 44 institutions have not received National Se...
Kweku Zurek
 
Vitamin and Nutritional Deficiencies.pptx
Vitamin and Nutritional Deficiencies.pptx
Vishal Chanalia
 
THE PSYCHOANALYTIC OF THE BLACK CAT BY EDGAR ALLAN POE (1).pdf
THE PSYCHOANALYTIC OF THE BLACK CAT BY EDGAR ALLAN POE (1).pdf
nabilahk908
 
How payment terms are configured in Odoo 18
How payment terms are configured in Odoo 18
Celine George
 
How to Manage Different Customer Addresses in Odoo 18 Accounting
How to Manage Different Customer Addresses in Odoo 18 Accounting
Celine George
 
University of Ghana Cracks Down on Misconduct: Over 100 Students Sanctioned
University of Ghana Cracks Down on Misconduct: Over 100 Students Sanctioned
Kweku Zurek
 
LDMMIA Yoga S10 Free Workshop Grad Level
LDMMIA Yoga S10 Free Workshop Grad Level
LDM & Mia eStudios
 
ENGLISH_Q1_W1 PowerPoint grade 3 quarter 1 week 1
ENGLISH_Q1_W1 PowerPoint grade 3 quarter 1 week 1
jutaydeonne
 
IIT KGP Quiz Week 2024 Sports Quiz (Prelims + Finals)
IIT KGP Quiz Week 2024 Sports Quiz (Prelims + Finals)
IIT Kharagpur Quiz Club
 
Public Health For The 21st Century 1st Edition Judy Orme Jane Powell
Public Health For The 21st Century 1st Edition Judy Orme Jane Powell
trjnesjnqg7801
 
Filipino 9 Maikling Kwento Ang Ama Panitikang Asiyano
Filipino 9 Maikling Kwento Ang Ama Panitikang Asiyano
sumadsadjelly121997
 
NSUMD_M1 Library Orientation_June 11, 2025.pptx
NSUMD_M1 Library Orientation_June 11, 2025.pptx
Julie Sarpy
 

Std 12 computer chapter 6 object oriented concepts (part 2)

  • 1. Object Oriented Concept Part 2 Aggregation & Composition Aggregation vs. Composition Inheritance Composition vs. Inheritance Presented by Nuzhat Ibrahim Memon
  • 2. Presented by Nuzhat Ibrahim Memon 2 Name • first name: String • last name: string • display() Person • nm: Name • addr:Address • birthdate:date • setbirthdate(d:int, m:int, y:int):date Address •house: string •street:string •state:string •pincode:int •fulladress(): string Teacher • Subject : string • lecture(d:date, t:time)
  • 3. • When objects of one class are composed of objects of other class, it is called aggregation or composition. • It represents “has-a” or “a-part-of” relationship between classes. Presented by Nuzhat Ibrahim Memon 3 Person • nm: Name • addr: Address • birthdate:date • setbirthdate(d:int, m:int, y:int):date • display() Name • First Name: string • Middle name:string • last name:string • fullName():string • display() Address • house: string • street:string • state:string • pincode:int • fulladress(): string • display() Screen • length: int • width: int • model: string Motherboard • model: string • company: string computer • scr: Screen • mb: Motherboard • Take an example of ‘person’ class • We will define two classed ‘Name’ and ‘Address’. • Class ‘Name’ has an attribute first name, middle name and last name. • Class ‘address’ has an attribute house, street, city, state and pincode. • The data type of attributes ‘nm’ and ‘addr’ is class ‘Name’ and ‘Address’ respectively. • Thus class ‘person’ contains object of class ‘Name’ and ‘Address’
  • 4. • Aggregation represents non-exclusive relationship between two classes. • In aggregation, the class that forms part of the owner class can exist independently. • The life of an object of the part class is not determined by the owner class. • Object Address may be shared by more than one person. Address is not exclusive to any one person. So, when a person is deleted, the corresponding address cannot be deleted. • Basic aggregation is represented using an empty diamond symbol next to the whole class. • Composition represents exclusive relationship between two classes. • Composition is a strong type of aggregation where the lifetime of the class depends on the existence of the owner class. • If an object of aggregating class is deleted, its part class object also will get deleted. For eg. When an object of class person is deleted, the object of class name is also deleted. Name is associated exclusively with single person. • Composition relationships are represented using a filled diamond next to the whole class. Owner class, Whole class or aggregating class Presented by Nuzhat Ibrahim Memon 4 Name • first name: string • Middle name: string • last name: string • display() Person • nm: Name • addr:Address • birthdate:date • setbirthdate(d:int, m:int, y:int):date Address •house: string •street:string •state:string •pincode:int •fulladress(): string Subject class, part class or aggregated class Subject class, part class or aggregated class Composition Relationship (Filled diamond) Aggregation Relationship (Empty diamond)
  • 5. • Inheritance is generally referred to as ‘is-a-kind-of’ relationship between two classes. • Inheritance is appropriate when one class is ‘a kind of’ other class. For e.g. teacher is a kind of person. So, all the attributes and methods of class ‘Person’ are applicable to class ‘Teacher’ also. • Inheritance refers to the capability of defining a new class of objects that inherits the characteristic of another existing class. • In other words, class ‘Teacher’ inherits all attributes and behavior of class ‘Person’. Class ‘Teacher’ may have additional attributes like subject and method like taking lectures of the subject. In such scenario, class ‘Teacher’ can be defined using class ‘Person’. • The feature provides reusability where existing methods can be reused without redefining. In other words, the data attributes and methods of the super class are available to objects in the sub class without rewriting their declarations. Presented by Nuzhat Ibrahim Memon 5 Person • name:string • city: string • gender:char=‘F’ • setBirthdate(d:int, m:int, y:int):date • display() Teacher • subject: string • lecture (d:date, t:time) Existing class is called New Class is called super class sub class parent class child class base class derived class In Class Diagram, Inheritance is represented using an arrow pointing to super class.
  • 6. Presented by Nuzhat Ibrahim Memon 6 • Generalization is another name for inheritance or “is a” relationship. • It refers to a relationship between two classes where one class is a specialized version of another. • Common attributes and methods are defined in super class. • Sub class is a specialized version with additional attributes and methods. • There may be a classical hierarchy of inheritance between classes. For e.g. class ‘Employee’ can be derived from class ‘Person’, then class ‘Teacher’ can be derived from ‘Employee’. Here employee is a kind of person and teacher is a kind of employee. Such type of inheritance is known as multilevel inheritance. • A class can also be derived using more than parent classes. For e.g. a child inherits the characteristics of both mother and father. When a class is derived from two or more classes. It is known as multiple inheritance. In multiple inheritance, child will get properties from father as well as mother from both the parents. • Example: airplane is a kind of vehicle as well as flying object. Person Teacher Employee Child Father Mother Airplane Vehicle Flying object Person (Super Class) Teacher (Sub Class) Common attributes & methods Additional attributes & methods Grandfather Son Father
  • 7. • In inheritance, class inherits from other classes in order to share, reuse or extend functionality. Here there exists ‘is a’ or ‘a kind of’ relationship between super class and sub class. • In composition, classes do not inherit from other classes, but are ‘composed of’ other classes. Class contains the attributes where some attributes are of objects of other class types. Presented by Nuzhat Ibrahim Memon 7 Social Networking Site Facebook Users is a has a