Object-Oriented Programming (OOP) Lecture No. 4
Object-Oriented Programming (OOP) Lecture No. 4
(OOP)
Lecture No. 4
Recap – Inheritance
► Derivedclass inherits all the characteristics
of the base class
► Generalization
► Subtyping (extension)
► Specialization (restriction)
Generalization
► In
OO models, some classes may have
common characteristics
Circle Triangle
radius Line angle
computeArea length computeArea
getLength
Example – Generalization
Student
name
age Teacher
gender name
Doctor
program age
name
studyYear gender
age
study designation
gender
heldExam salary
teach designation
eat
takeExam salary
walk
eat checkUp
walk prescribe
eat
walk
Example – Generalization
Person
name
age
gender
eat
walk
► Inherit
the new class from this class and
add unique behaviour to the new class
Sub-typing (Extension)
► Sub-typingmeans that derived class is
behaviourally compatible with the base class
Sub-typing
(Extension) Student
program
studyYear
study
takeExam
Shape
color
vertices
setColor
Example – move
Sub-typing
(Extension)
Circle
radius
computeCF
computeArea
Specialization (Restriction)
► Specialization
means that derived class is
behaviourally incompatible with the base
class
Circle Triangle
radius Line angle
draw length draw
computeArea draw computeArea
Example – Extension
Window
width
height
open
close
draw
Circle
radius
draw
rotate
Abstract Classes
Student Doctor
Teacher
► Here, Person is an abstract class
Example – Abstract Classes
Vehicle
color
model
accelerate
applyBrakes
Car Truck
Bus
► Provides
implementation details specific to
the domain context
Example – Concrete Classes
Person
Student Doctor
program Teacher
studyYear
study
heldExam
Vehicle
Car Truck
Bus
capacity
load
unload