SlideShare a Scribd company logo
Object-Oriented Programming
(OOP)
Lecture No. 5
Recap – Inheritance
►Derived class inherits all the characteristics
of the base class
►Besides inherited characteristics, derived
class may have its own unique
characteristics
►Major benefit of inheritance is reuse
Concepts Related with
Inheritance
►Generalization
►Subtyping (extension)
►Specialization (restriction)
Generalization
►In OO models, some classes may have
common characteristics
►We extract these features into a new class
and inherit original classes from this new
class
►This concept is known as Generalization
Example – Generalization
Circle
color
vertices
radius
move
setColor
computeArea
Line
color
vertices
length
move
setColor
getLength
Triangle
color
vertices
angle
move
setColor
computeArea
Example – Generalization
Shape
color
vertices
move
setColor
Circle
radius
computeArea
Line
length
getLength
Triangle
angle
computeArea
Example – Generalization
Teacher
name
age
gender
designation
salary
teach
takeExam
eat
walk
Student
name
age
gender
program
studyYear
study
heldExam
eat
walk
Doctor
name
age
gender
designation
salary
checkUp
prescribe
eat
walk
Example – Generalization
Person
name
age
gender
eat
walk
Teacher
designation
salary
teach
takeExam
Student
program
studyYear
study
heldExam
Doctor
designation
salary
checkUp
prescribe
Sub-typing & Specialization
►We want to add a new class to an existing
model
►Find an existing class that already
implements some of the desired state and
behaviour
►Inherit the new class from this class and
add unique behaviour to the new class
Sub-typing (Extension)
►Sub-typing means that derived class is
behaviourally compatible with the base class
►Behaviourally compatible means that base
class can be replaced by the derived class
Example –
Sub-typing
(Extension)
Person
name
age
gender
eats
walks
Student
program
studyYear
study
takeExam
Example –
Sub-typing
(Extension)
Shape
color
vertices
setColor
move
Circle
radius
computeCF
computeArea
Specialization (Restriction)
►Specialization means that derived class is
behaviourally incompatible with the base
class
►Behaviourally incompatible means that base
class can’t always be replaced by the
derived class
Example – Specialization
(Restriction)
Person
age : [0..100]
…
Adult
age : [18..100]
…
setAge( a )
…
setAge( a )
…
age = a
If age < 18 then
error
else
age = a
Example – Specialization
(Restriction)
IntegerSet
…
NaturalSet
…
add( elem )
…
add( elem )
…
add element
to the set
If elem < 1 then
error
else
add element
to the set
Overriding
►A class may need to override the default
behaviour provided by its base class
►Reasons for overriding
 Provide behaviour specific to a derived class
 Extend the default behaviour
 Restrict the default behaviour
 Improve performance
Example – Specific Behaviour
Shape
color
vertices
draw
move
setColor
Circle
radius
draw
computeArea
Line
length
draw
Triangle
angle
draw
computeArea
Example – Extension
Window
width
height
open
close
draw
DialogBox
controls
enable
draw
1- Invoke Window’s
draw
2- draw the dialog
box
Example – Restriction
IntegerSet
…
NaturalSet
…
add( elem )
…
add( elem )
…
Add element
to the set
If elem < 1 then
give error
else
Add element
to the set
Example – Improve Performance
► Class Circle overrides
rotate operation of
class Shape with a Null
operation.
Shape
color
coord
draw
rotate
setColor
Circle
radius
draw
rotate
Abstract Classes
►An abstract class implements an abstract
concept
►Main purpose is to be inherited by other
classes
►Can’t be instantiated
►Promotes reuse
Example – Abstract Classes
Teacher
Doctor
Student
►Here, Person is an abstract class
Person
name
age
gender
eat
walk
Example – Abstract Classes
Bus
Truck
Car
►Here, Vehicle is an abstract class
Vehicle
color
model
accelerate
applyBrakes
Concrete Classes
►A concrete class implements a concrete
concept
►Main purpose is to be instantiated
►Provides implementation details specific to
the domain context
Example – Concrete Classes
►Here, Student, Teacher and Doctor are
concrete classes
Teacher
Doctor
Student
program
studyYear
study
heldExam
Person
Example – Concrete Classes
• Here, Car, Bus and Truck are concrete
classes
Bus
Car
Vehicle
Truck
capacity
load
unload

More Related Content

PPTX
Concept of Classes in c++.ist mse16.pptx
PPTX
L02 Software Design
PDF
Machine Learning
PPT
Inheritance & Polymorphism - 1
PPTX
Generalization abstraction
PPTX
Week_1 Machine Learning introduction.pptx
PDF
Core java complete notes - PAID call at +91-814-614-5674
PDF
Core java complete notes - Contact at +91-814-614-5674
Concept of Classes in c++.ist mse16.pptx
L02 Software Design
Machine Learning
Inheritance & Polymorphism - 1
Generalization abstraction
Week_1 Machine Learning introduction.pptx
Core java complete notes - PAID call at +91-814-614-5674
Core java complete notes - Contact at +91-814-614-5674

Similar to Lec5_OOP.pptx (20)

PDF
lec02-DecisionTreed. Checking primality of an integer n .pdf
PPTX
Learning
PPTX
Pi j3.1 inheritance
PPT
Lecture01
PPT
Department of Computer science and engineering
PPT
Basic Class Diagrams in software engineering
PPT
Basic Class Diagrams in fundamental computing.ppt
PPTX
Lecture 06.pptxLecture 06.pptxLecture 06.pptx
PDF
Computer Vision Computer Vision: Algorithms and Applications Richard Szeliski
PPT
Session 21
PPT
Ch 9-1.Machine Learning: Symbol-based
PPT
Ch 9-1.Machine Learning: Symbol-based
PDF
Lecture on Python OP concepts of Polymorpysim and Inheritance.pdf
PPTX
Unit-V.pptx DVD is a great way to get sbi and more jobs available review and ...
PDF
Boosted tree
PPT
Machine Learning: Decision Trees Chapter 18.1-18.3
PDF
L1 intro2 supervised_learning
PDF
Introduction to Boosted Trees by Tianqi Chen
PPT
Part 1
PPTX
Recommender Systems from A to Z – Model Training
lec02-DecisionTreed. Checking primality of an integer n .pdf
Learning
Pi j3.1 inheritance
Lecture01
Department of Computer science and engineering
Basic Class Diagrams in software engineering
Basic Class Diagrams in fundamental computing.ppt
Lecture 06.pptxLecture 06.pptxLecture 06.pptx
Computer Vision Computer Vision: Algorithms and Applications Richard Szeliski
Session 21
Ch 9-1.Machine Learning: Symbol-based
Ch 9-1.Machine Learning: Symbol-based
Lecture on Python OP concepts of Polymorpysim and Inheritance.pdf
Unit-V.pptx DVD is a great way to get sbi and more jobs available review and ...
Boosted tree
Machine Learning: Decision Trees Chapter 18.1-18.3
L1 intro2 supervised_learning
Introduction to Boosted Trees by Tianqi Chen
Part 1
Recommender Systems from A to Z – Model Training

More from AneesAbbasi14 (10)

PPTX
Goal Setting UPDATED.pptx
PDF
Lec_15_OOP_ObjectsAsParametersFriendClasses.pdf
PDF
lecture-2021inheritance-160705095417.pdf
PDF
lecture-18staticdatamember-160705095116.pdf
PPTX
lec09_ransac.pptx
PPTX
lec07_transformations.pptx
PPTX
02-07-20_Anees.pptx
PPTX
Yasir Presentation.pptx
PDF
Lec_1,2_OOP_(Introduction).pdf
PPTX
IntroComputerVision23.pptx
Goal Setting UPDATED.pptx
Lec_15_OOP_ObjectsAsParametersFriendClasses.pdf
lecture-2021inheritance-160705095417.pdf
lecture-18staticdatamember-160705095116.pdf
lec09_ransac.pptx
lec07_transformations.pptx
02-07-20_Anees.pptx
Yasir Presentation.pptx
Lec_1,2_OOP_(Introduction).pdf
IntroComputerVision23.pptx

Recently uploaded (20)

PPTX
GDM (1) (1).pptx small presentation for students
PDF
Basic Mud Logging Guide for educational purpose
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PDF
O7-L3 Supply Chain Operations - ICLT Program
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PDF
01-Introduction-to-Information-Management.pdf
PDF
Sports Quiz easy sports quiz sports quiz
PDF
Insiders guide to clinical Medicine.pdf
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PDF
Classroom Observation Tools for Teachers
PPTX
Pharma ospi slides which help in ospi learning
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PDF
Pre independence Education in Inndia.pdf
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PPTX
PPH.pptx obstetrics and gynecology in nursing
PDF
Computing-Curriculum for Schools in Ghana
GDM (1) (1).pptx small presentation for students
Basic Mud Logging Guide for educational purpose
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
O7-L3 Supply Chain Operations - ICLT Program
Renaissance Architecture: A Journey from Faith to Humanism
01-Introduction-to-Information-Management.pdf
Sports Quiz easy sports quiz sports quiz
Insiders guide to clinical Medicine.pdf
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
Classroom Observation Tools for Teachers
Pharma ospi slides which help in ospi learning
Abdominal Access Techniques with Prof. Dr. R K Mishra
STATICS OF THE RIGID BODIES Hibbelers.pdf
Pre independence Education in Inndia.pdf
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
Microbial diseases, their pathogenesis and prophylaxis
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PPH.pptx obstetrics and gynecology in nursing
Computing-Curriculum for Schools in Ghana

Lec5_OOP.pptx