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

More Related Content

PPTX
Std 12 computer chapter 6 object oriented concepts (part 1)
PPTX
Std 12 Computer Chapter 7 Java Basics (Part 1)
PPTX
Std 12 Computer Chapter 5 Introduction to Mcommerce (Part 1)
PPSX
Javascript variables and datatypes
PPTX
Std 12 computer chapter 8 classes and object in java (part 2)
PPT
9. Input Output in java
PPT
Arrays
PPTX
Arrays In C++
Std 12 computer chapter 6 object oriented concepts (part 1)
Std 12 Computer Chapter 7 Java Basics (Part 1)
Std 12 Computer Chapter 5 Introduction to Mcommerce (Part 1)
Javascript variables and datatypes
Std 12 computer chapter 8 classes and object in java (part 2)
9. Input Output in java
Arrays
Arrays In C++

What's hot (20)

PPTX
Std 12 Computer Chapter 2 Cascading Style Sheets and Javascript(Part 1 CSS)
PPT
Bubble sort
PPTX
Java constructors
PPT
Introduction to Javascript
PDF
Function overloading ppt
PDF
Arrays in Java
PPTX
Classes objects in java
PDF
PPT
Queue AS an ADT (Abstract Data Type)
PPTX
Java(Polymorphism)
PPTX
Methods in java
PDF
C++ Files and Streams
PPTX
Array in Java
PPT
Visual programming
PPT
File handling in C++
PPTX
[OOP - Lec 16,17] Objects as Function Parameter and ReturnType
PPSX
Break and continue
PDF
Python unit 3 m.sc cs
PPTX
Std 12 Computer Chapter 2 Cascading Style Sheet and Javascript (Part-2)
PPT
Labels and buttons
Std 12 Computer Chapter 2 Cascading Style Sheets and Javascript(Part 1 CSS)
Bubble sort
Java constructors
Introduction to Javascript
Function overloading ppt
Arrays in Java
Classes objects in java
Queue AS an ADT (Abstract Data Type)
Java(Polymorphism)
Methods in java
C++ Files and Streams
Array in Java
Visual programming
File handling in C++
[OOP - Lec 16,17] Objects as Function Parameter and ReturnType
Break and continue
Python unit 3 m.sc cs
Std 12 Computer Chapter 2 Cascading Style Sheet and Javascript (Part-2)
Labels and buttons
Ad

More from Nuzhat Memon (20)

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

Recently uploaded (20)

PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PDF
TR - Agricultural Crops Production NC III.pdf
PDF
Anesthesia in Laparoscopic Surgery in India
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PPTX
GDM (1) (1).pptx small presentation for students
PDF
Pre independence Education in Inndia.pdf
PDF
Sports Quiz easy sports quiz sports quiz
PDF
Insiders guide to clinical Medicine.pdf
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PDF
RMMM.pdf make it easy to upload and study
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PPTX
Pharma ospi slides which help in ospi learning
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
human mycosis Human fungal infections are called human mycosis..pptx
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
TR - Agricultural Crops Production NC III.pdf
Anesthesia in Laparoscopic Surgery in India
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
GDM (1) (1).pptx small presentation for students
Pre independence Education in Inndia.pdf
Sports Quiz easy sports quiz sports quiz
Insiders guide to clinical Medicine.pdf
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
102 student loan defaulters named and shamed – Is someone you know on the list?
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
STATICS OF THE RIGID BODIES Hibbelers.pdf
RMMM.pdf make it easy to upload and study
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
2.FourierTransform-ShortQuestionswithAnswers.pdf
Pharma ospi slides which help in ospi learning
O5-L3 Freight Transport Ops (International) V1.pdf
FourierSeries-QuestionsWithAnswers(Part-A).pdf

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