Oop Class Inheritance
Oop Class Inheritance
Programming (OOP)
Abstraction
Abstraction
complexity.
Principle
of abstraction:
Example Abstraction
Ali is a PhD student and teaches BS
students
Attributes
- Name
- Student Roll No
- Year of Study
- CGPA
- Employee ID
- Designation
- Salary
- Age
Example Abstraction
Ali is a PhD student and teaches BS
students
behaviour
- Study
- GiveExam
- PlaySports
- DeliverLecture
- DevelopExam
- TakeExam
- Eat
- Walk
Example Abstraction
Students Perspective
Attributes
- Name
- Student Roll No
- Year of Study
- CGPA
- Employee ID
- Designation
- Salary
- Age
Example Abstraction
Students Perspective
behaviour
- Study
- GiveExam
- PlaySports
- DeliverLecture
- DevelopExam
- TakeExam
- Eat
- Walk
Example Abstraction
Teachers Perspective
Attributes
- Name
- Student Roll No
- Year of Study
- CGPA
- Employee ID
- Designation
- Salary
- Age
Example Abstraction
Teachers Perspective
behaviour
- Study
- GiveExam
- PlaySports
- DeliverLecture
- DevelopExam
- TakeExam
- Eat
- Walk
Example Abstraction
A cat can be viewed with different
perspectives
Ordinary
Perspective
Surgeons
Perspective
A being with
A Skeleton
Heart
Kidney
Stomach
Example Abstraction
Engineers View
Drivers View
Abstraction Advantages
Simplifies
Abstraction
Classes
In
We
Example Class
Ali
studies mathematics
Anam studies physics
Sohail studies chemistry
Each
one is a Student
We say these objects are instances of
the Student class
Example Class
Ahsan
teaches mathematics
Aamir teaches computer science
Atif teaches physics
Each
one is a teacher
We say these objects are instances of
the Teacher class
Graphical Representation of
Classes
(Class Name)
(attributes)
(operations)
Normal Form
(Class Name)
Suppressed
Form
Example Graphical
Representation of Classes
Circle
center
radius
draw
computeArea
Normal Form
Circle
Suppressed
Form
Example Graphical
Representation of Classes
Person
name
age
gender
eat
walk
Normal Form
Person
Suppressed
Form
Inheritance
A
Besides
inherited characteristics, a
child may have its own unique
characteristics
Inheritance in Classes
If
Example Inheritance
Person
Student
Doctor
Teacher
Example Inheritance
Shape
Line
Triangle
Circle
Inheritance IS A or
IS A KIND OF Relationship
Each
Example IS A Relationship
Person
name
age
gender
eat
walk
Student
program
studyYear
study
heldExam
Teacher
designation
salary
teach
takeExam
Doctor
designation
salary
checkUp
prescribe
Example IS A Relationship
Shape
color
coord
draw
rotate
setColor
Circle
radius
draw
computeArea
Triangle
Line
length
draw
angle
draw
computeArea
Inheritance Advantages
Reuse
Less
redundancy
Increased
maintainability
Example Reuse
Shape
color
coord
draw
rotate
setColor
Circle
radius
draw
computeArea
Triangle
Line
length
draw
angle
draw
computeArea
Example Reuse
Person
name
age
gender
eat
walk
Student
program
studyYear
study
heldExam
Teacher
designation
salary
teach
takeExam
Doctor
designation
salary
checkUp
prescribe
Example Reuse
Person
name
age
gender
eat
walk
Student
program
studyYear
study
heldExam
Teacher
designation
salary
teach
takeExam
Doctor
designation
salary
checkUp
prescribe