OOP-Lecture 04
OOP-Lecture 04
Programming
Dr. Mujeeb Ur Rehman
[email protected]
Recommended Books:
1.C++ How to Program ( Deitel & Deitel );
2.Object-Oriented Software Engineering By Jacobson, Christerson, Jonsson,
Overgaard
Hazrat/Sir Allama Muhammad Iqbal (R.A)
Object-Oriented
Programming (OOP)
Lecture No. 4
Concepts Related with
Inheritance
► 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
► 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-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)
► Specializationmeans that derived
class is behaviourally incompatible
with the base class
Circle Triangle
radius Line angle
draw length draw
computeArea draw computeArea
Abstract Classes
Student Doctor
Teacher
► Here, Person is an abstract class
Example – Abstract Classes
Vehicle
color
model
accelerate
applyBrakes
Car Truck
Bus
Person
Student Doctor
program Teacher
studyYear
study
heldExam
Vehicle
Car Truck
Bus
capacity
load
unload